From 8ed8c9af6a878abdcbf414169932697c6def8dd1 Mon Sep 17 00:00:00 2001 From: Vijay Oommen Date: Mon, 24 Mar 2025 08:33:17 -0500 Subject: [PATCH] [PM-18685] Disable MyVault when the Person Ownership policy is true (#13930) --- .../src/components/export.component.html | 18 ++++-- .../src/components/export.component.ts | 57 +++++++++++++++---- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.html b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.html index 7555b206976..5b196f51799 100644 --- a/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.html +++ b/libs/tools/export/vault-export/vault-export-ui/src/components/export.component.html @@ -1,17 +1,23 @@ - + {{ "personalVaultExportPolicyInEffect" | i18n }} - +
{{ "exportFrom" | i18n }} - + ; + disablePersonalOwnershipPolicy$: Observable; + exportForm = this.formBuilder.group({ vaultSelector: [ "myVault", @@ -201,15 +205,13 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit { this.formDisabled.emit(c === "DISABLED"); }); - this.policyService - .policyAppliesToActiveUser$(PolicyType.DisablePersonalVaultExport) - .pipe(takeUntil(this.destroy$)) - .subscribe((policyAppliesToActiveUser) => { - this._disabledByPolicy = policyAppliesToActiveUser; - if (this.disabledByPolicy) { - this.exportForm.disable(); - } - }); + // policies + this.disablePersonalVaultExportPolicy$ = this.policyService.policyAppliesToActiveUser$( + PolicyType.DisablePersonalVaultExport, + ); + this.disablePersonalOwnershipPolicy$ = this.policyService.policyAppliesToActiveUser$( + PolicyType.PersonalOwnership, + ); merge( this.exportForm.get("format").valueChanges, @@ -269,13 +271,45 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit { }), ); + combineLatest([ + this.disablePersonalVaultExportPolicy$, + this.disablePersonalOwnershipPolicy$, + this.organizations$, + ]) + .pipe( + tap(([disablePersonalVaultExport, disablePersonalOwnership, organizations]) => { + this._disabledByPolicy = disablePersonalVaultExport; + + // When personalOwnership is disabled and we have orgs, set the first org as the selected vault + if (disablePersonalOwnership && organizations.length > 0) { + this.exportForm.enable(); + this.exportForm.controls.vaultSelector.setValue(organizations[0].id); + } + + // When personalOwnership is disabled and we have no orgs, disable the form + if (disablePersonalOwnership && organizations.length === 0) { + this.exportForm.disable(); + } + + // When personalVaultExport is disabled, disable the form + if (disablePersonalVaultExport) { + this.exportForm.disable(); + } + + // When neither policy is enabled, enable the form and set the default vault to "myVault" + if (!disablePersonalVaultExport && !disablePersonalOwnership) { + this.exportForm.controls.vaultSelector.setValue("myVault"); + } + }), + takeUntil(this.destroy$), + ) + .subscribe(); + this.exportForm.controls.vaultSelector.valueChanges .pipe(takeUntil(this.destroy$)) .subscribe((value) => { this.organizationId = value != "myVault" ? value : undefined; }); - - this.exportForm.controls.vaultSelector.setValue("myVault"); } ngAfterViewInit(): void { @@ -286,6 +320,7 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit { ngOnDestroy(): void { this.destroy$.next(); + this.destroy$.complete(); } get encryptedFormat() {