From a572e4119edd6da65295268c8cab95a7ab16afc5 Mon Sep 17 00:00:00 2001 From: Tom <144813356+ttalty@users.noreply.github.com> Date: Wed, 10 Jan 2024 16:12:24 -0500 Subject: [PATCH] [PM-4535] Import into org vault with remove individual vault policy set (#7343) * Refactored import ngOnInit. Set the default org if import allowed. Verified org id exists on import * moving handlePolicies to the end of ngOnInit --- .../src/components/import.component.ts | 54 ++++++++++++------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/libs/importer/src/components/import.component.ts b/libs/importer/src/components/import.component.ts index 557ed86f84..438076c934 100644 --- a/libs/importer/src/components/import.component.ts +++ b/libs/importer/src/components/import.component.ts @@ -196,27 +196,10 @@ export class ImportComponent implements OnInit, OnDestroy { return this.showLastPassToggle && this.formGroup.controls.lastPassType.value === "direct"; } - ngOnInit() { + async ngOnInit() { this.setImportOptions(); - this.organizations$ = concat( - this.organizationService.memberOrganizations$.pipe( - canAccessImportExport(this.i18nService), - map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))), - ), - ); - - combineLatest([ - this.policyService.policyAppliesToActiveUser$(PolicyType.PersonalOwnership), - this.organizations$, - ]) - .pipe(takeUntil(this.destroy$)) - .subscribe(([policyApplies, orgs]) => { - this._importBlockedByPolicy = policyApplies; - if (policyApplies && orgs.length == 0) { - this.formGroup.disable(); - } - }); + await this.initializeOrganizations(); if (this.organizationId) { this.formGroup.controls.vaultSelector.patchValue(this.organizationId); @@ -257,6 +240,37 @@ export class ImportComponent implements OnInit, OnDestroy { .subscribe((value) => { this.format = value; }); + + await this.handlePolicies(); + } + + private async initializeOrganizations() { + this.organizations$ = concat( + this.organizationService.memberOrganizations$.pipe( + canAccessImportExport(this.i18nService), + map((orgs) => orgs.sort(Utils.getSortFunction(this.i18nService, "name"))), + ), + ); + } + + private async handlePolicies() { + combineLatest([ + this.policyService.policyAppliesToActiveUser$(PolicyType.PersonalOwnership), + this.organizations$, + ]) + .pipe(takeUntil(this.destroy$)) + .subscribe(([policyApplies, orgs]) => { + this._importBlockedByPolicy = policyApplies; + if (policyApplies && orgs.length == 0) { + this.formGroup.disable(); + } + + // If there are orgs the user has access to import into set + // the default value to the first org in the collection. + if (policyApplies && orgs.length > 0) { + this.formGroup.controls.vaultSelector.setValue(orgs[0].id); + } + }); } submit = async () => { @@ -291,7 +305,7 @@ export class ImportComponent implements OnInit, OnDestroy { } } - if (this.importBlockedByPolicy) { + if (this.importBlockedByPolicy && this.organizationId == null) { this.platformUtilsService.showToast( "error", null,