Merge pull request #9639 from opf/fix/38805/notification-loaded-as-anonymous

[38805] Fix notification loading as anonymous user
pull/9642/head
Henriette Darge 3 years ago committed by GitHub
commit cf8cd7eb68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts
  2. 15
      spec/features/work_packages/tabs/activity_notifications_spec.rb

@ -1,7 +1,11 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { WpSingleViewStore } from './wp-single-view.store'; import { WpSingleViewStore } from './wp-single-view.store';
import { WpSingleViewQuery } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.query'; import { WpSingleViewQuery } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.query';
import { take } from 'rxjs/operators'; import {
filter,
switchMap,
take,
} from 'rxjs/operators';
import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store'; import { selectCollectionAsHrefs$ } from 'core-app/core/state/collection-store';
import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service'; import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface'; import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
@ -14,6 +18,7 @@ import {
EffectCallback, EffectCallback,
EffectHandler, EffectHandler,
} from 'core-app/core/state/effects/effect-handler.decorator'; } from 'core-app/core/state/effects/effect-handler.decorator';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
@EffectHandler @EffectHandler
@Injectable() @Injectable()
@ -26,6 +31,7 @@ export class WpSingleViewService {
constructor( constructor(
readonly actions$:ActionsService, readonly actions$:ActionsService,
readonly currentUser$:CurrentUserService,
private resourceService:InAppNotificationsResourceService, private resourceService:InAppNotificationsResourceService,
) { ) {
} }
@ -63,8 +69,13 @@ export class WpSingleViewService {
private reload() { private reload() {
this this
.resourceService .currentUser$
.fetchNotifications(this.query.params) .isLoggedIn$
.pipe(
take(1),
filter((loggedIn) => loggedIn),
switchMap(() => this.resourceService.fetchNotifications(this.query.params)),
)
.subscribe(); .subscribe();
} }

@ -90,4 +90,19 @@ describe 'Activity tab notifications', js: true, selenium: true do
it_behaves_like 'when there are no notifications for the work package' it_behaves_like 'when there are no notifications for the work package'
end end
context 'when visiting as an anonymous user', with_settings: { login_required?: false } do
let(:full_view) { Pages::FullWorkPackage.new(work_package, project) }
let!(:anonymous_role) do
FactoryBot.create :anonymous_role, permissions: [:view_work_packages]
end
it 'does not show an error' do
full_view.visit_tab! 'activity'
full_view.ensure_page_loaded
full_view.expect_no_notification type: :error, message: 'Http failure response for'
full_view.expect_no_notification
end
end
end end

Loading…
Cancel
Save