[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
This commit is contained in:
Tom 2024-01-10 16:12:24 -05:00 committed by GitHub
parent d87f885c9c
commit a572e4119e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 20 deletions

View File

@ -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,