diff --git a/apps/web/src/app/admin-console/organizations/settings/account.component.html b/apps/web/src/app/admin-console/organizations/settings/account.component.html index 082fe7eb80..d8cd5fddfe 100644 --- a/apps/web/src/app/admin-console/organizations/settings/account.component.html +++ b/apps/web/src/app/admin-console/organizations/settings/account.component.html @@ -104,12 +104,11 @@ - - diff --git a/apps/web/src/app/admin-console/organizations/settings/account.component.ts b/apps/web/src/app/admin-console/organizations/settings/account.component.ts index d8091e46ae..5ff8d00eab 100644 --- a/apps/web/src/app/admin-console/organizations/settings/account.component.ts +++ b/apps/web/src/app/admin-console/organizations/settings/account.component.ts @@ -28,8 +28,6 @@ import { DeleteOrganizationDialogResult, openDeleteOrganizationDialog } from "./ templateUrl: "account.component.html", }) export class AccountComponent { - @ViewChild("purgeOrganizationTemplate", { read: ViewContainerRef, static: true }) - purgeModalRef: ViewContainerRef; @ViewChild("apiKeyTemplate", { read: ViewContainerRef, static: true }) apiKeyModalRef: ViewContainerRef; @ViewChild("rotateApiKeyTemplate", { read: ViewContainerRef, static: true }) @@ -232,11 +230,14 @@ export class AccountComponent { } } - async purgeVault() { - await this.modalService.openViewRef(PurgeVaultComponent, this.purgeModalRef, (comp) => { - comp.organizationId = this.organizationId; + purgeVault = async () => { + const dialogRef = PurgeVaultComponent.open(this.dialogService, { + data: { + organizationId: this.organizationId, + }, }); - } + await lastValueFrom(dialogRef.closed); + }; async viewApiKey() { await this.modalService.openViewRef(ApiKeyComponent, this.apiKeyModalRef, (comp) => { diff --git a/apps/web/src/app/auth/settings/account/account.component.html b/apps/web/src/app/auth/settings/account/account.component.html index deb2f0ef30..a521061194 100644 --- a/apps/web/src/app/auth/settings/account/account.component.html +++ b/apps/web/src/app/auth/settings/account/account.component.html @@ -12,7 +12,7 @@ - - - - - - - +
+ + +

+ {{ (organizationId ? "purgeOrgVaultDesc" : "purgeVaultDesc") | i18n }} +

+ {{ "purgeVaultWarning" | i18n }} + +
+ + + + +
+
diff --git a/apps/web/src/app/vault/settings/purge-vault.component.ts b/apps/web/src/app/vault/settings/purge-vault.component.ts index 4ef9e20e2a..869cbaab1b 100644 --- a/apps/web/src/app/vault/settings/purge-vault.component.ts +++ b/apps/web/src/app/vault/settings/purge-vault.component.ts @@ -1,55 +1,60 @@ -import { Component, Input } from "@angular/core"; +import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog"; +import { Component, Inject } from "@angular/core"; +import { FormControl, FormGroup } from "@angular/forms"; import { Router } from "@angular/router"; import { ApiService } from "@bitwarden/common/abstractions/api.service"; import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction"; import { Verification } from "@bitwarden/common/auth/types/verification"; import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service"; -import { LogService } from "@bitwarden/common/platform/abstractions/log.service"; import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service"; import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction"; +import { DialogService } from "@bitwarden/components"; + +export interface PurgeVaultDialogData { + organizationId: string; +} @Component({ selector: "app-purge-vault", templateUrl: "purge-vault.component.html", }) export class PurgeVaultComponent { - @Input() organizationId?: string = null; + organizationId: string = null; - masterPassword: Verification; - formPromise: Promise; + formGroup = new FormGroup({ + masterPassword: new FormControl(null), + }); constructor( + @Inject(DIALOG_DATA) protected data: PurgeVaultDialogData, + private dialogRef: DialogRef, private apiService: ApiService, private i18nService: I18nService, private platformUtilsService: PlatformUtilsService, private userVerificationService: UserVerificationService, private router: Router, - private logService: LogService, private syncService: SyncService, - ) {} + ) { + this.organizationId = data && data.organizationId ? data.organizationId : null; + } - async submit() { - try { - this.formPromise = this.userVerificationService - .buildRequest(this.masterPassword) - .then((request) => this.apiService.postPurgeCiphers(request, this.organizationId)); - await this.formPromise; - this.platformUtilsService.showToast("success", null, this.i18nService.t("vaultPurged")); - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.syncService.fullSync(true); - if (this.organizationId != null) { - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.router.navigate(["organizations", this.organizationId, "vault"]); - } else { - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - this.router.navigate(["vault"]); - } - } catch (e) { - this.logService.error(e); + submit = async () => { + const response = this.userVerificationService + .buildRequest(this.formGroup.value.masterPassword) + .then((request) => this.apiService.postPurgeCiphers(request, this.organizationId)); + await response; + this.platformUtilsService.showToast("success", null, this.i18nService.t("vaultPurged")); + await this.syncService.fullSync(true); + if (this.organizationId != null) { + await this.router.navigate(["organizations", this.organizationId, "vault"]); + } else { + await this.router.navigate(["vault"]); } + this.dialogRef.close(); + }; + + static open(dialogService: DialogService, config?: DialogConfig) { + return dialogService.open(PurgeVaultComponent, config); } }