Skip to content

Commit

Permalink
fix(delete value button): evaluate users permissions to enable/disabl…
Browse files Browse the repository at this point in the history
…e delete button (#1138)
  • Loading branch information
domsteinbach committed Jul 17, 2023
1 parent f7eca25 commit 6736942
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Expand Up @@ -170,7 +170,7 @@
[matTooltip]="
canDelete
? 'delete'
: 'This value cannot be deleted because at least one value is required'
: cantDeleteReason
"
>
<button
Expand Down
Expand Up @@ -91,6 +91,8 @@ export class DisplayEditComponent implements OnInit {

@Input() canDelete: boolean;

@Input() cantDeleteReason: string;

@Input() projectStatus: boolean;

@Input() valueUuidToHighlight: string;
Expand Down
Expand Up @@ -129,9 +129,16 @@ <h3 class="label mat-headline-6">
<div class="property-value">
<!-- the value(s) of the property -->
<div *ngFor="let val of prop.values">
<app-display-edit *ngIf="val" #displayEdit [parentResource]="resource.res" [displayValue]="val"
[propArray]="resource.resProps" [canDelete]="deleteValueIsAllowed(prop)"
[projectStatus]="project?.status" [valueUuidToHighlight]="valueUuidToHighlight"
<app-display-edit
*ngIf="val"
#displayEdit
[parentResource]="resource.res"
[displayValue]="val"
[propArray]="resource.resProps"
[canDelete]="deleteValueIsAllowed(prop)"
[cantDeleteReason]='cantDeleteReason'
[projectStatus]="project?.status"
[valueUuidToHighlight]="valueUuidToHighlight"
(referredResourceClicked)="openResource($event)"
(referredResourceHovered)="previewResource()">
</app-display-edit>
Expand Down
Expand Up @@ -138,6 +138,8 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
deletedResource = false;

userCanDelete: boolean;
cantDeleteReason = '';

userCanEdit: boolean;
addValueFormIsVisible: boolean; // used to toggle add value form field
propID: string; // used in template to show only the add value form of the corresponding value
Expand Down Expand Up @@ -199,7 +201,7 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
// if user has modify permissions, set addButtonIsVisible to true so the user see's the add button
this.userCanEdit = allPermissions.indexOf(PermissionUtil.Permissions.M) !== -1;

// if user has delete permissions, set deleteButtonIsVisible to true so the user see's the delete button
// if user has delete permissions
this.userCanDelete =
allPermissions.indexOf(PermissionUtil.Permissions.D) !== -1;
}
Expand Down Expand Up @@ -571,11 +573,20 @@ export class PropertiesComponent implements OnInit, OnChanges, OnDestroy {
* @param prop the resource property
*/
deleteValueIsAllowed(prop: PropertyInfoValues): boolean {
return CardinalityUtil.deleteValueForPropertyAllowed(
const card = CardinalityUtil.deleteValueForPropertyAllowed(
prop.propDef.id,
prop.values.length,
this.resource.res.entityInfo.classes[this.resource.res.type]
);
)
if (!card) {
this.cantDeleteReason = 'This value can not be deleted because it is required.';
}

if (!this.userCanDelete) {
this.cantDeleteReason = 'You do not have teh permission to delete this value.';
}

return card && this.userCanDelete;
}

/**
Expand Down

0 comments on commit 6736942

Please sign in to comment.