From 306b63048991a96297b4e9cf8192cc68e7e7de8d Mon Sep 17 00:00:00 2001 From: jaasen-livefront Date: Thu, 16 Jan 2025 11:27:47 -0800 Subject: [PATCH] use canDeleteCipher$ --- .../vault-item-dialog.component.ts | 42 ++++--------------- 1 file changed, 8 insertions(+), 34 deletions(-) diff --git a/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts b/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts index c7d0ac0f1d6..292851044aa 100644 --- a/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts +++ b/apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts @@ -204,6 +204,14 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy { ), ); + protected async showRestore() { + return ( + this.filter?.type === "trash" && + this.cipher?.isDeleted && + (await firstValueFrom(this.canDeleteCipher$)) + ); + } + protected get loadingForm() { return this.loadForm && !this.formReady; } @@ -229,40 +237,6 @@ export class VaultItemDialogComponent implements OnInit, OnDestroy { return this.cipher != undefined && (this.params.mode === "view" || this.loadingForm); } - protected get showRestore() { - return this.filter?.type === "trash" && this.canRestoreCipher && !!this.params.restore; - } - - /** - * Whether the user can restore a given cipher from the trash - * Rules for when a cipher can be restored: - * - the cipher is deleted - * - AND one or more of the following: - * - the cipher is a personal item (doesn't belong to an organization) - * - the cipher belongs to a collection that the user can manage - * - the user is an admin of the organization to which the cipher belongs - */ - protected get canRestoreCipher() { - if (!this.cipher || !this.cipher.isDeleted) { - return false; - } - - if (this.cipher.organizationId == null) { - return true; - } - - const collection = this.collections.find((c) => this.cipher.collectionIds.includes(c.id)); - if (collection?.manage) { - return true; - } - - if (this.organization?.isAdmin) { - return true; - } - - return false; - } - /** * Flag to initialize/attach the form component. */