Skip to content

Commit

Permalink
[PM-13829] Add organizationId to isAdmin check, refactor isAdmin to g…
Browse files Browse the repository at this point in the history
…etter (#11997)

* Add organizationId to isAdmin check, refactor isAdmin to getter for restore and delete

* add comment
  • Loading branch information
BTreston authored Nov 14, 2024
1 parent 48294aa commit 5c540a8
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions libs/angular/src/vault/components/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,19 +713,26 @@ export class AddEditComponent implements OnInit, OnDestroy {
}

protected deleteCipher() {
// cipher.collectionIds may be null or an empty array. Either is a valid indication that the item is unassigned.
const asAdmin =
this.organization?.canEditAllCiphers ||
!this.cipher.collectionIds ||
this.cipher.collectionIds.length === 0;
return this.cipher.isDeleted
? this.cipherService.deleteWithServer(this.cipher.id, asAdmin)
: this.cipherService.softDeleteWithServer(this.cipher.id, asAdmin);
? this.cipherService.deleteWithServer(this.cipher.id, this.asAdmin)
: this.cipherService.softDeleteWithServer(this.cipher.id, this.asAdmin);
}

protected restoreCipher() {
const asAdmin = this.organization?.canEditAllCiphers;
return this.cipherService.restoreWithServer(this.cipher.id, asAdmin);
return this.cipherService.restoreWithServer(this.cipher.id, this.asAdmin);
}

/**
* Determines if a cipher must be deleted as an admin by belonging to an organization and being unassigned to a collection.
*/
get asAdmin(): boolean {
return (
this.cipher.organizationId !== null &&
this.cipher.organizationId.length > 0 &&
(this.organization?.canEditAllCiphers ||
!this.cipher.collectionIds ||
this.cipher.collectionIds.length === 0)
);
}

get defaultOwnerId(): string | null {
Expand Down

0 comments on commit 5c540a8

Please sign in to comment.