[PM-13829] Add organizationId to isAdmin check, refactor isAdmin to getter (#11997)

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

* add comment
This commit is contained in:
Brandon Treston 2024-11-14 17:17:40 -05:00 committed by GitHub
parent 48294aac86
commit 5c540a86f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 9 deletions

View File

@ -713,19 +713,26 @@ export class AddEditComponent implements OnInit, OnDestroy {
} }
protected deleteCipher() { 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 return this.cipher.isDeleted
? this.cipherService.deleteWithServer(this.cipher.id, asAdmin) ? this.cipherService.deleteWithServer(this.cipher.id, this.asAdmin)
: this.cipherService.softDeleteWithServer(this.cipher.id, asAdmin); : this.cipherService.softDeleteWithServer(this.cipher.id, this.asAdmin);
} }
protected restoreCipher() { protected restoreCipher() {
const asAdmin = this.organization?.canEditAllCiphers; return this.cipherService.restoreWithServer(this.cipher.id, this.asAdmin);
return this.cipherService.restoreWithServer(this.cipher.id, 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 { get defaultOwnerId(): string | null {