Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit a17f89b

Browse files
committed
Only user with WRITE access to tool can edit Tool metadata
1 parent b6038e4 commit a17f89b

File tree

4 files changed

+66
-70
lines changed

4 files changed

+66
-70
lines changed

client/app/tool/tool-home/tool-home.component.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ToolAuthorizationService } from './../tool-authorization.service';
12
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
23
import { Router, ActivatedRoute } from '@angular/router';
34
import { MatDialog } from '@angular/material';
@@ -15,6 +16,7 @@ import { omit } from 'lodash';
1516
import { ToolDataService } from '../tool-data.service';
1617
import config from '../../app.constants';
1718
import { TokenService } from 'components/auth/token.service';
19+
import { ToolAuthorization } from '../tool-authorization.service';
1820

1921
@Component({
2022
selector: 'tool-home',
@@ -27,16 +29,17 @@ export class ToolHomeComponent implements OnInit, OnDestroy {
2729
private showEditToolTemplate = false;
2830
private toolHealth: ToolHealth;
2931

30-
private canEditTool = true;
31-
private canDeleteTool = false;
32-
private userPermissionsSub: Subscription;
32+
private toolAuthorization: ToolAuthorization;
33+
private toolAuthorizationSub: Subscription;
34+
3335
private entityType = config.entityTypes.TOOL.value;
3436

3537
static parameters = [
3638
Router,
3739
ActivatedRoute,
3840
PageTitleService,
3941
ToolService,
42+
ToolAuthorizationService,
4043
ToolDataService,
4144
UserPermissionDataService,
4245
NotificationService,
@@ -48,20 +51,24 @@ export class ToolHomeComponent implements OnInit, OnDestroy {
4851
private route: ActivatedRoute,
4952
private pageTitleService: PageTitleService,
5053
private toolService: ToolService,
54+
private toolAuthorizationService: ToolAuthorizationService,
5155
private toolDataService: ToolDataService,
5256
private userPermissionDataService: UserPermissionDataService,
5357
private notificationService: NotificationService,
5458
private dialog: MatDialog,
5559
private tokenService: TokenService
56-
) {
57-
this.tool$ = this.toolDataService.tool();
58-
this.userPermissionsSub = this.userPermissionDataService.permissions().subscribe(permissions => {
59-
// this.canEditTool = permissions.canEditTool();
60-
// this.canDeleteTool = permissions.canDeleteTool();
61-
});
62-
}
60+
) {}
6361

6462
ngOnInit() {
63+
this.tool$ = this.toolDataService.tool();
64+
65+
this.toolAuthorizationSub = this.toolAuthorizationService.authorization().subscribe(
66+
auth => {
67+
this.toolAuthorization = auth;
68+
},
69+
err => console.error(err)
70+
);
71+
6572
// const getTool = this.toolDataService.tool();
6673

6774
// const getToolHealth = this.tool$.pipe( // TODO To review
@@ -89,7 +96,9 @@ export class ToolHomeComponent implements OnInit, OnDestroy {
8996
}
9097

9198
ngOnDestroy() {
92-
this.userPermissionsSub.unsubscribe();
99+
if (this.toolAuthorizationSub) {
100+
this.toolAuthorizationSub.unsubscribe();
101+
}
93102
}
94103

95104
onEditTool(tool: Tool): void {

client/app/tool/tool-home/tool-home.html

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,60 +28,46 @@ <h3>{{ tool.title }}</h3>
2828
</div>
2929
</div>
3030
<div class="tool-actions">
31-
<div class="app-tool-icon-actions">
32-
<share-button [entity]="tool" [entityType]="entityType"></share-button>
33-
<a
34-
mat-icon-button
35-
[matMenuTriggerFor]="moreActionsMenu"
36-
matTooltip="More actions"
37-
aria-label="More actions"
38-
>
39-
<mat-icon aria-label="Icon of three horizontal dots">more_horiz</mat-icon>
40-
</a>
41-
<mat-menu #moreActionsMenu="matMenu" [overlapTrigger]="false">
42-
<button
43-
ngxClipboard
44-
[cbContent]="getLink()"
45-
(cbOnSuccess)="notificationService.info('Link successfully copied')"
46-
(cbOnError)="notificationService.info('Unable to copy the link.')"
47-
mat-menu-item
48-
aria-label="Copy link"
49-
>
50-
<span>Copy Link</span>
51-
</button>
52-
<mat-divider></mat-divider>
53-
<button
54-
mat-menu-item
55-
[attr.aria-label]="'Edit'"
56-
*ngIf="canEditTool"
57-
(click)="showEditToolTemplate=true"
58-
>
59-
<span>Edit</span>
60-
</button>
61-
<button
62-
mat-menu-item
63-
[attr.aria-label]="'Delete'"
64-
disabled
65-
>
66-
<span class="app-tool-actions-delete-btn-label">Delete</span>
67-
</button>
68-
</mat-menu>
69-
</div>
70-
<div class="app-tool-button-actions">
71-
<a mat-raised-button color="primary" (click)="openTool(tool)" target="_blank">Open Tool</a>
72-
</div>
73-
</div>
31+
<div class="app-tool-icon-actions">
32+
<share-button [entity]="tool" [entityType]="entityType"></share-button>
33+
<a
34+
mat-icon-button
35+
[matMenuTriggerFor]="moreActionsMenu"
36+
matTooltip="More actions"
37+
aria-label="More actions"
38+
>
39+
<mat-icon aria-label="Icon of three horizontal dots">more_horiz</mat-icon>
40+
</a>
41+
<mat-menu #moreActionsMenu="matMenu" [overlapTrigger]="false">
42+
<button
43+
ngxClipboard
44+
[cbContent]="getLink()"
45+
(cbOnSuccess)="notificationService.info('Link successfully copied')"
46+
(cbOnError)="notificationService.info('Unable to copy the link.')"
47+
mat-menu-item
48+
aria-label="Copy link"
49+
>
50+
<span>Copy Link</span>
51+
</button>
52+
<mat-divider *ngIf="toolAuthorization.canWrite"></mat-divider>
53+
<button
54+
mat-menu-item
55+
aria-label="Edit Tool"
56+
*ngIf="toolAuthorization.canWrite"
57+
(click)="showEditToolTemplate = true"
58+
>
59+
<span>Edit Tool</span>
60+
</button>
61+
</mat-menu>
62+
</div>
63+
<div class="app-tool-button-actions">
64+
<a mat-raised-button color="primary" (click)="openTool(tool)" target="_blank">Open Tool</a>
65+
</div>
66+
</div>
7467
</mat-card>
7568
</div>
7669

7770
<ng-template #showEditToolForm>
78-
<tool-edit
79-
[tool]="tool"
80-
(editTool)="onEditTool($event)"
81-
(close)="showEditToolTemplate = false"
82-
></tool-edit>
71+
<tool-edit [tool]="tool" (editTool)="onEditTool($event)" (close)="showEditToolTemplate = false"></tool-edit>
8372
</ng-template>
8473
</div>
85-
86-
87-

client/app/tool/tool-list/tool-list.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ToolAuthorization } from './../tool-authorization.service';
12
import { Component, OnInit, OnDestroy } from '@angular/core';
23
import { Router } from '@angular/router';
34
import { Subscription } from 'rxjs';
@@ -14,8 +15,8 @@ import { ToolAuthorizationService } from '../tool-authorization.service';
1415
styles: [require('./tool-list.scss')],
1516
})
1617
export class ToolListComponent implements OnInit, OnDestroy {
17-
private canCreateTool = false; // used in html
18-
private canCreateToolSub: Subscription;
18+
private toolAuthorization: ToolAuthorization;
19+
private toolAuthorizationSub: Subscription;
1920

2021
static parameters = [Router, PageTitleService, NotificationService, ToolService, ToolAuthorizationService];
2122
constructor(
@@ -28,17 +29,17 @@ export class ToolListComponent implements OnInit, OnDestroy {
2829

2930
ngOnInit() {
3031
this.pageTitleService.title = 'Tools';
31-
this.canCreateToolSub = this.toolAuthorizationService.authorization().subscribe(
32+
this.toolAuthorizationSub = this.toolAuthorizationService.authorization().subscribe(
3233
auth => {
33-
this.canCreateTool = auth.canCreate;
34+
this.toolAuthorization = auth;
3435
},
3536
err => console.error(err)
3637
);
3738
}
3839

3940
ngOnDestroy() {
40-
if (this.canCreateToolSub) {
41-
this.canCreateToolSub.unsubscribe();
41+
if (this.toolAuthorizationSub) {
42+
this.toolAuthorizationSub.unsubscribe();
4243
}
4344
}
4445

@@ -49,7 +50,7 @@ export class ToolListComponent implements OnInit, OnDestroy {
4950
}
5051

5152
newTool(): void {
52-
if (this.canCreateTool) {
53+
if (this.toolAuthorization.canCreate) {
5354
this.router.navigate(['/', 'tools', 'new']);
5455
} else {
5556
this.notificationService.info('Not available to Users yet.');

client/app/tool/tool-list/tool-list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ <h1 class="app-primary-header-title">Tools</h1>
66
class="app-tool-list-new-tool-btn"
77
(click)="newTool()"
88
aria-label="Create a new tool"
9-
><mat-icon class="app-tool-list-new-tool-btn-icon" *ngIf="!canCreateTool">lock</mat-icon> New Tool</a
9+
><mat-icon class="app-tool-list-new-tool-btn-icon" *ngIf="!toolAuthorization.canCreate">lock</mat-icon> New Tool</a
1010
>
1111
</div>
1212

0 commit comments

Comments
 (0)