From 4327fa21f6ac425f1760bf33067fe62feb37ea2c Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Thu, 19 Sep 2024 10:43:28 -0700 Subject: [PATCH] [PM-11343] Browser Refresh - View dialog permissions in AC (#11092) * [PM-11343] Add param to conditionally disable the edit button * [PM-11343] Cleanup router navigation and move query param handling to callers of the View dialog * [PM-11343] Fix failing test * [PM-11343] Fix missing router after merge * [PM-11343] Add null checks in case the dialog result is undefined (due to closing via the ESC key) * [PM-11343] Add support to provide a list of collections to the cipher view component * [PM-11343] Add collections as an optional view cipher dialog parameter * [PM-11343] Update the org vault to provide collections when opening the View cipher dialog * [PM-11343] Fix import * [PM-11343] Use [replaceUrl] for cipher items to avoid needing double back button --- .../vault-cipher-row.component.html | 1 + .../vault/individual-vault/vault.component.ts | 19 +++-- .../individual-vault/view.component.html | 12 ++- .../individual-vault/view.component.spec.ts | 16 +--- .../vault/individual-vault/view.component.ts | 39 ++++----- .../app/vault/org-vault/vault.component.ts | 80 ++++++++----------- .../cipher-view/cipher-view.component.html | 2 +- .../src/cipher-view/cipher-view.component.ts | 27 +++++-- 8 files changed, 90 insertions(+), 106 deletions(-) diff --git a/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html b/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html index 524d9dff20..20942da3fe 100644 --- a/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html +++ b/apps/web/src/app/vault/components/vault-items/vault-cipher-row.component.html @@ -21,6 +21,7 @@ [routerLink]="[]" [queryParams]="{ itemId: cipher.id, action: extensionRefreshEnabled ? 'view' : null }" queryParamsHandling="merge" + [replaceUrl]="extensionRefreshEnabled" title="{{ 'editItemWithName' | i18n: cipher.name }}" type="button" appStopProp diff --git a/apps/web/src/app/vault/individual-vault/vault.component.ts b/apps/web/src/app/vault/individual-vault/vault.component.ts index a288b298ba..8ad9deaf2b 100644 --- a/apps/web/src/app/vault/individual-vault/vault.component.ts +++ b/apps/web/src/app/vault/individual-vault/vault.component.ts @@ -47,7 +47,7 @@ import { MessagingService } from "@bitwarden/common/platform/abstractions/messag import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { Utils } from "@bitwarden/common/platform/misc/utils"; import { SyncService } from "@bitwarden/common/platform/sync"; -import { CipherId, OrganizationId, CollectionId } from "@bitwarden/common/types/guid"; +import { CipherId, CollectionId, OrganizationId } from "@bitwarden/common/types/guid"; import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service"; import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service"; import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service"; @@ -722,10 +722,6 @@ export class VaultComponent implements OnInit, OnDestroy { this.go({ cipherId: null, itemId: null, action: null }); } - async navigateToCipher(cipher: CipherView) { - this.go({ itemId: cipher?.id }); - } - async editCipher(cipher: CipherView, cloneMode?: boolean) { return this.editCipherId(cipher?.id, cloneMode); } @@ -861,16 +857,19 @@ export class VaultComponent implements OnInit, OnDestroy { // Wait for the dialog to close. const result: ViewCipherDialogCloseResult = await lastValueFrom(dialogRef.closed); + // If the dialog was closed by clicking the edit button, navigate to open the edit dialog. + if (result?.action === ViewCipherDialogResult.Edited) { + this.go({ itemId: cipherView.id, action: "edit" }); + return; + } + // If the dialog was closed by deleting the cipher, refresh the vault. if (result?.action === ViewCipherDialogResult.Deleted) { this.refresh(); - this.go({ cipherId: null, itemId: null, action: null }); } - // If the dialog was closed by any other action (close button, escape key, etc), navigate back to the vault. - if (!result?.action) { - this.go({ cipherId: null, itemId: null, action: null }); - } + // Clear the query params when the view dialog closes + this.go({ cipherId: null, itemId: null, action: null }); } async addCollection() { diff --git a/apps/web/src/app/vault/individual-vault/view.component.html b/apps/web/src/app/vault/individual-vault/view.component.html index d1caf76192..ca3a5fb865 100644 --- a/apps/web/src/app/vault/individual-vault/view.component.html +++ b/apps/web/src/app/vault/individual-vault/view.component.html @@ -3,13 +3,19 @@ {{ cipherTypeString }} - + - -
+