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

Conditionally render the Share button based on capabilities

Aaron Contreras1c7875c4c891
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 1d2c379679b..242f2b0e2a5 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
@@ -33,7 +33,7 @@ import {
Injector,
OnInit,
} from '@angular/core';
-import { of } from 'rxjs';
+import { Observable, of } from 'rxjs';
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';
@@ -42,6 +42,7 @@ import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-
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';
@Component({
templateUrl: './wp-full-view.html',
@@ -62,7 +63,7 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
public displayTimerButton = false;
- public displayShareButton = false;
+ public displayShareButton$:false|Observable<boolean> = false;
public watchers:any;
@@ -79,6 +80,7 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
public wpTableSelection:WorkPackageViewSelectionService,
public recentItemsService:RecentItemsService,
readonly $state:StateService,
+ readonly currentUserService:CurrentUserService,
private readonly configurationService:ConfigurationService,
) {
super(injector, $state.params.workPackageId);
@@ -105,7 +107,8 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
this.isWatched = Object.prototype.hasOwnProperty.call(wp, 'unwatch');
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.configurationService.activeFeatureFlags.includes('workPackageSharing');
+ this.displayShareButton$ = this.configurationService.activeFeatureFlags.includes('workPackageSharing')
+ && this.currentUserService.hasCapabilities$('shares/index', wp.project.id);
// watchers
if (wp.watchers) {
diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
index 8468ea829d5..28d4a51e810 100644
--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.html
@@ -25,7 +25,8 @@
[stateName$]="stateName$">
</wp-create-button>
</li>
- <li class="toolbar-item" *ngIf="displayShareButton">
+ <li class="toolbar-item"
+ *ngIf="displayShareButton$ | async">
<wp-share-button [workPackage]="workPackage">
</wp-share-button>
</li>