From 1bdafbc9e63c83bd74f491177e7d6ab67055b351 Mon Sep 17 00:00:00 2001 From: sgiannopoulos Date: Thu, 14 Mar 2024 11:41:32 +0200 Subject: [PATCH] dmp authz changes --- .../ui/dmp/listing/dmp-listing.component.ts | 11 +++++++++- .../dmp-listing-item.component.html | 2 +- .../dmp-listing-item.component.ts | 21 +++++++------------ .../dmp/overview/dmp-overview.component.html | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts b/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts index 9ed061046..56619aef4 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/dmp-listing.component.ts @@ -31,6 +31,7 @@ import { DmpVersionStatus } from '@app/core/common/enum/dmp-version-status'; import { DmpReference } from '@app/core/model/dmp/dmp-reference'; import { Reference } from '@app/core/model/reference/reference'; import { ReferenceType } from '@app/core/model/reference-type/reference-type'; +import { AppPermission } from '@app/core/common/enum/permission.enum'; @Component({ selector: 'app-dmp-listing-component', @@ -185,6 +186,14 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr nameof(x => x.groupId), nameof(x => x.updatedAt), nameof(x => x.hash), + [nameof(x => x.authorizationFlags), AppPermission.CreateNewVersionDmp].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.DeleteDmp].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.CloneDmp].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.FinalizeDmp].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.ExportDmp].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.InviteDmpUsers].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.AssignDmpUsers].join('.'), + [nameof(x => x.authorizationFlags), AppPermission.EditDmp].join('.'), [nameof(x => x.descriptions), nameof(x => x.id)].join('.'), [nameof(x => x.descriptions), nameof(x => x.label)].join('.'), @@ -238,7 +247,7 @@ export class DmpListingComponent extends BaseComponent implements OnInit { //IBr this.hasListingItems = true; }); } - + } controlModified(): void { diff --git a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.html b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.html index 521638806..10d6bfa4f 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.html +++ b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.html @@ -50,7 +50,7 @@ - diff --git a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts index e7a6b69e7..52f85c1cf 100644 --- a/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts @@ -107,7 +107,7 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { } viewVersions(dmp: Dmp) { - if (dmp.accessType == DmpAccessType.Public && dmp.status == DmpStatus.Finalized && !this.isDmpOwner(dmp)) { + if (dmp.accessType == DmpAccessType.Public && dmp.status == DmpStatus.Finalized && !this.dmp.authorizationFlags?.some(x => x === AppPermission.EditDmp)) { let url = this.router.createUrlTree(['/explore-plans/versions/', dmp.groupId]); window.open(url.toString(), '_blank'); } else { @@ -217,36 +217,31 @@ export class DmpListingItemComponent extends BaseComponent implements OnInit { this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error); } - isDmpOwner(dmp: Dmp): boolean { - const principalId: Guid = this.authentication.userId(); - if (principalId) return !!dmp.dmpUsers?.find(x => (x.role === DmpUserRole.Owner) && (principalId === x.id)); - } - canCreateNewVersion(dmp: Dmp): boolean { - return (this.isDmpOwner(dmp) || this.authentication.hasPermission(AppPermission.CreateNewVersionDmp)) && this.isPublic == false; + return (this.dmp.authorizationFlags?.some(x => x === AppPermission.CreateNewVersionDmp) || this.authentication.hasPermission(AppPermission.CreateNewVersionDmp)) && this.isPublic == false; } canDeleteDmp(dmp: Dmp): boolean { - return (this.isDmpOwner(dmp) || this.authentication.hasPermission(AppPermission.DeleteDmp)) && this.isPublic == false; + return (this.dmp.authorizationFlags?.some(x => x === AppPermission.DeleteDmp) || this.authentication.hasPermission(AppPermission.DeleteDmp)) && this.isPublic == false; } canCloneDmp(dmp: Dmp): boolean { - return this.isDmpOwner(dmp) || this.authentication.hasPermission(AppPermission.CloneDmp); + return this.dmp.authorizationFlags?.some(x => x === AppPermission.CloneDmp) || this.authentication.hasPermission(AppPermission.CloneDmp); } canFinalizeDmp(dmp: Dmp): boolean { - return (this.isDmpOwner(dmp) || this.authentication.hasPermission(AppPermission.FinalizeDmp)) && this.isPublic == false; + return (this.dmp.authorizationFlags?.some(x => x === AppPermission.FinalizeDmp) || this.authentication.hasPermission(AppPermission.FinalizeDmp)) && this.isPublic == false; } canExportDmp(dmp: Dmp): boolean { - return this.isDmpOwner(dmp) || this.authentication.hasPermission(AppPermission.ExportDmp); + return this.dmp.authorizationFlags?.some(x => x === AppPermission.ExportDmp) || this.authentication.hasPermission(AppPermission.ExportDmp); } canInviteDmpUsers(dmp: Dmp): boolean { - return (this.isDmpOwner(dmp) || this.authentication.hasPermission(AppPermission.InviteDmpUsers)) && this.isPublic == false; + return (this.dmp.authorizationFlags?.some(x => x === AppPermission.InviteDmpUsers) || this.authentication.hasPermission(AppPermission.InviteDmpUsers)) && this.isPublic == false; } canAssignDmpUsers(dmp: Dmp): boolean { - return (this.isDmpOwner(dmp) || this.authentication.hasPermission(AppPermission.AssignDmpUsers)) && this.isPublic == false; + return (this.dmp.authorizationFlags?.some(x => x === AppPermission.AssignDmpUsers) || this.authentication.hasPermission(AppPermission.AssignDmpUsers)) && this.isPublic == false; } } diff --git a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html index a14ab6a54..b858194f5 100644 --- a/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html +++ b/dmp-frontend/src/app/ui/dmp/overview/dmp-overview.component.html @@ -190,7 +190,7 @@

{{ enumUtils.toDmpUserRoleString(dmpUser.role) }}

- +