Skip to content

Commit d14adb9

Browse files
committed
fix(admin): authorization for delete facility
* There was used a policy which evaluates also given object (facility), so there is not possible to paste an empty array. * Now the button is removed, when user doesn't have any suficient role (facility admin or perun admin) and if user has facility admin, authorization for selected facility will be evaluated additionally. * This issue was discovered thanks to e2e tests and this PR should fix then again.
1 parent 15727f2 commit d14adb9

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

apps/admin-gui/src/app/facilities/pages/facility-select-page/facility-select-page.component.html

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@ <h1 class="page-title d-flex">
1919
color="accent">
2020
{{'FACILITY_MANAGEMENT.CREATE' | translate}}
2121
</button>
22-
<button
23-
mat-flat-button
24-
class="me-2"
25-
data-cy="delete-facility-button"
26-
[disabled]="selection.selected.length === 0"
27-
*ngIf="deleteAuth"
28-
(click)="onDelete()"
29-
color="warn">
30-
{{'FACILITY_MANAGEMENT.DELETE' | translate}}
31-
</button>
22+
<span
23+
[matTooltipDisabled]="selection.selected.length === 0 || ([selection.selected[0]?.facility] | isAuthorized: 'deleteFacility_Facility_Boolean_policy')"
24+
[matTooltipPosition]="'below'"
25+
matTooltip="{{'FACILITY_MANAGEMENT.DELETE_PERMISSION_HINT' | translate}}">
26+
<button
27+
mat-flat-button
28+
class="me-2"
29+
data-cy="delete-facility-button"
30+
[disabled]="selection.selected.length === 0 || !([selection.selected[0]?.facility] | isAuthorized: 'deleteFacility_Facility_Boolean_policy')"
31+
*ngIf="deleteAuth"
32+
(click)="onDelete()"
33+
color="warn">
34+
{{'FACILITY_MANAGEMENT.DELETE' | translate}}
35+
</button>
36+
</span>
3237
<perun-web-apps-immediate-filter
3338
[autoFocus]="true"
3439
(filter)="applyFilter($event)"

apps/admin-gui/src/app/facilities/pages/facility-select-page/facility-select-page.component.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ export class FacilitySelectPageComponent implements OnInit, AfterViewChecked {
3737

3838
ngOnInit(): void {
3939
this.createAuth = this.guiAuthResolver.isAuthorized('createFacility_Facility_policy', []);
40-
this.deleteAuth = this.guiAuthResolver.isAuthorized(
41-
'deleteFacility_Facility_Boolean_policy',
42-
[]
43-
);
40+
this.deleteAuth = this.guiAuthResolver.isFacilityAdmin();
4441
this.refreshTable();
4542
}
4643

apps/admin-gui/src/assets/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"TITLE": "Select facility",
7373
"FILTER_PLACEHOLDER": "Filter by name, Id, description, owner, host or destination",
7474
"CREATE": "Create",
75-
"DELETE": "Delete"
75+
"DELETE": "Delete",
76+
"DELETE_PERMISSION_HINT": "You don't have permission to delete selected facility"
7677
},
7778
"CONSENTS": {
7879
"STATUS": "Consent status",

0 commit comments

Comments
 (0)