Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Ensure anonymous are restricted from creating reminders

Kabiru Mwenjad10375c8cedc
diff --git a/frontend/src/app/core/current-user/current-user.service.ts b/frontend/src/app/core/current-user/current-user.service.ts
index 9f62c5df719..e5836715942 100644
--- a/frontend/src/app/core/current-user/current-user.service.ts
+++ b/frontend/src/app/core/current-user/current-user.service.ts
@@ -28,13 +28,13 @@
import { Injectable } from '@angular/core';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { CurrentUser, CurrentUserStore } from './current-user.store';
-import { CurrentUserQuery } from './current-user.query';
-import { CapabilitiesResourceService } from 'core-app/core/state/capabilities/capabilities.service';
-import { Observable } from 'rxjs';
-import { distinctUntilChanged, map, switchMap, take } from 'rxjs/operators';
import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
+import { CapabilitiesResourceService } from 'core-app/core/state/capabilities/capabilities.service';
import { ICapability } from 'core-app/core/state/capabilities/capability.model';
+import { Observable, combineLatest } from 'rxjs';
+import { distinctUntilChanged, map, switchMap, take } from 'rxjs/operators';
+import { CurrentUserQuery } from './current-user.query';
+import { CurrentUser, CurrentUserStore } from './current-user.store';
@Injectable({ providedIn: 'root' })
export class CurrentUserService {
@@ -63,6 +63,15 @@ export class CurrentUserService {
}));
}
+ public isLoggedInAndHasCapabalities$(action:string|string[], projectContext:string|null):Observable<boolean> {
+ return combineLatest([
+ this.hasCapabilities$(action, projectContext),
+ this.isLoggedIn$,
+ ]).pipe(
+ map(([hasCapabilities, isLoggedIn]) => hasCapabilities && isLoggedIn),
+ );
+ }
+
/**
* Returns the set of capabilities for the given context and/or actions
*/
diff --git a/frontend/src/app/features/work-packages/components/wp-details/wp-details-toolbar.component.ts b/frontend/src/app/features/work-packages/components/wp-details/wp-details-toolbar.component.ts
index 7c0fb14e65d..c673630f1c5 100644
--- a/frontend/src/app/features/work-packages/components/wp-details/wp-details-toolbar.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-details/wp-details-toolbar.component.ts
@@ -26,15 +26,16 @@
// See COPYRIGHT and LICENSE files for more details.
//++
+import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
+import { ConfigurationService } from 'core-app/core/config/configuration.service';
+import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import {
HalResourceEditingService,
} from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { Component, Input, OnInit, ChangeDetectionStrategy } from '@angular/core';
-import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
-import { ConfigurationService } from 'core-app/core/config/configuration.service';
-import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
-import { Observable } from 'rxjs';
+import { Observable, of } from 'rxjs';
@Component({
selector: 'wp-details-toolbar',
@@ -47,7 +48,7 @@ export class WorkPackageSplitViewToolbarComponent implements OnInit {
@Input() displayNotificationsButton:boolean;
public displayShareButton$:false|Observable<boolean> = false;
- public displayReminderButton$:false|Observable<boolean> = false;
+ public displayReminderButton$:Observable<boolean> = of(false);
public text = {
button_more: this.I18n.t('js.button_more'),
@@ -64,7 +65,9 @@ export class WorkPackageSplitViewToolbarComponent implements OnInit {
ngOnInit() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
this.displayShareButton$ = this.currentUserService.hasCapabilities$('work_package_shares/index', this.workPackage.project.id);
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
- this.displayReminderButton$ = this.currentUserService.hasCapabilities$('work_package_reminders/modal_body', this.workPackage.project.id);
+ this.displayReminderButton$ = this.currentUserService.isLoggedInAndHasCapabalities$(
+ 'work_package_reminders/modal_body',
+ (this.workPackage.project as ProjectResource).id,
+ );
}
}
diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts
index 16a8bc70c0e..51546acd32c 100644
--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts
@@ -26,9 +26,6 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
-import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
-import { StateService } from '@uirouter/core';
import {
ChangeDetectionStrategy,
Component,
@@ -36,16 +33,19 @@ import {
Injector,
OnInit,
} from '@angular/core';
-import { Observable, of } from 'rxjs';
+import { StateService } from '@uirouter/core';
+import { ConfigurationService } from 'core-app/core/config/configuration.service';
+import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
+import { RecentItemsService } from 'core-app/core/recent-items.service';
+import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
+import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';
+import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';
import { WorkPackageViewSelectionService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-selection.service';
import { WorkPackageSingleViewBase } from 'core-app/features/work-packages/routing/wp-view-base/work-package-single-view.base';
-import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
-import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';
-import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';
-import { RecentItemsService } from 'core-app/core/recent-items.service';
-import { ConfigurationService } from 'core-app/core/config/configuration.service';
-import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
+import { Observable, of } from 'rxjs';
@Component({
templateUrl: './wp-full-view.html',
@@ -63,7 +63,7 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
// Watcher properties
public isWatched:boolean;
- public displayReminderButton$:false|Observable<boolean> = false;
+ public displayReminderButton$:Observable<boolean> = of(false);
public displayShareButton$:false|Observable<boolean> = false;
@@ -122,7 +122,10 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
this.displayWatchButton = Object.prototype.hasOwnProperty.call(wp, 'unwatch') || Object.prototype.hasOwnProperty.call(wp, 'watch');
this.displayTimerButton = Object.prototype.hasOwnProperty.call(wp, 'logTime');
this.displayShareButton$ = this.currentUserService.hasCapabilities$('work_package_shares/index', (wp.project as ProjectResource).id);
- this.displayReminderButton$ = this.currentUserService.hasCapabilities$('work_package_reminders/modal_body', (wp.project as ProjectResource).id);
+ this.displayReminderButton$ = this.currentUserService.isLoggedInAndHasCapabalities$(
+ 'work_package_reminders/modal_body',
+ (this.workPackage.project as ProjectResource).id,
+ );
// watchers
if (wp.watchers) {
diff --git a/spec/features/work_packages/reminders_spec.rb b/spec/features/work_packages/reminders_spec.rb
index 39554165642..7b4bfa8a0df 100644
--- a/spec/features/work_packages/reminders_spec.rb
+++ b/spec/features/work_packages/reminders_spec.rb
@@ -383,17 +383,17 @@ RSpec.describe "Work package reminder modal",
end
end
- context "with anonymous user with role that can view work packages" do
- let!(:anonymous_user) do
- create(:anonymous).tap do
- ProjectRole.anonymous.add_permission! :view_work_packages
- end
+ context "with anonymous user with role that can view work packages", with_settings: { login_required: false } do
+ before do
+ ProjectRole.anonymous.add_permission! :view_work_packages
+ project.update!(public: true)
end
- current_user { anonymous_user }
+ current_user { User.anonymous }
it "does not render the reminder button when visiting the work package page" do
work_package_page.visit!
+ work_package_page.ensure_loaded
work_package_page.expect_no_reminder_button
end
end