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

[#42158] add manage file links permission switch

Eric Schubert15e95eb99889
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts
index 4879a90c85d..b0dfe7179ed 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts
+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.component.ts
@@ -50,6 +50,8 @@ export class FileLinkListItemComponent implements OnInit {
@Input() public index:number;
+ @Input() public allowEditing = false;
+
@Output() public removeFileLink = new EventEmitter<void>();
public infoTimestampText:string;
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html
index 9494b927bba..84758a80f36 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html
+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list-item.html
@@ -40,6 +40,7 @@
</button>
<button
+ *ngIf="allowEditing"
class="spot-link"
[title]="text.title.removeFileLink"
(click)="removeFileLink.emit()"
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts
index fd976a187bc..cc5db66b477 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts
+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.component.ts
@@ -29,24 +29,35 @@
import {
ChangeDetectionStrategy, Component, Input, OnInit,
} from '@angular/core';
-import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { Observable } from 'rxjs';
+import { tap } from 'rxjs/operators';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { IFileLink } from 'core-app/core/state/file-links/file-link.model';
import { FileLinkResourceService } from 'core-app/core/state/file-links/file-links.service';
+import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
-import { tap } from 'rxjs/operators';
@Component({
selector: 'op-file-link-list',
templateUrl: './file-link-list.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class FileLinkListComponent implements OnInit {
+export class FileLinkListComponent extends UntilDestroyedMixin implements OnInit {
@Input() public resource:HalResource;
$fileLinks:Observable<IFileLink[]>;
- constructor(private readonly fileLinkResourceService:FileLinkResourceService) {}
+ allowEditing = false;
+
+ constructor(
+ private readonly fileLinkResourceService:FileLinkResourceService,
+ private currentUserService:CurrentUserService,
+ private currentProjectService:CurrentProjectService,
+ ) {
+ super();
+ }
ngOnInit():void {
this.fileLinkResourceService.fetchCurrent(this.fileLinkSelfLink);
@@ -59,6 +70,14 @@ export class FileLinkListComponent implements OnInit {
}
}),
);
+
+ this
+ .currentUserService
+ .hasCapabilities$('file_links/manage', this.currentProjectService.id as string)
+ .pipe(this.untilDestroyed())
+ .subscribe((value) => {
+ this.allowEditing = value;
+ });
}
public removeFileLink(fileLink:IFileLink):void {
diff --git a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html
index 5fdb9dcd9d3..b62f9c1ac2e 100644
--- a/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html
+++ b/frontend/src/app/shared/components/file-links/file-link-list/file-link-list.html
@@ -6,6 +6,7 @@
[fileLink]="fileLink"
[resource]="resource"
[index]="i"
+ [allowEditing]="allowEditing"
(removeFileLink)="removeFileLink(fileLink)"
>
</op-file-link-list-item>