[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:
parent
d87f885c9c
commit
a572e4119e
|
@ -196,27 +196,10 @@ export class ImportComponent implements OnInit, OnDestroy {
|
||||||
return this.showLastPassToggle && this.formGroup.controls.lastPassType.value === "direct";
|
return this.showLastPassToggle && this.formGroup.controls.lastPassType.value === "direct";
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
async ngOnInit() {
|
||||||
this.setImportOptions();
|
this.setImportOptions();
|
||||||
|
|
||||||
this.organizations$ = concat(
|
await this.initializeOrganizations();
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (this.organizationId) {
|
if (this.organizationId) {
|
||||||
this.formGroup.controls.vaultSelector.patchValue(this.organizationId);
|
this.formGroup.controls.vaultSelector.patchValue(this.organizationId);
|
||||||
|
@ -257,6 +240,37 @@ export class ImportComponent implements OnInit, OnDestroy {
|
||||||
.subscribe((value) => {
|
.subscribe((value) => {
|
||||||
this.format = 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 () => {
|
submit = async () => {
|
||||||
|
@ -291,7 +305,7 @@ export class ImportComponent implements OnInit, OnDestroy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.importBlockedByPolicy) {
|
if (this.importBlockedByPolicy && this.organizationId == null) {
|
||||||
this.platformUtilsService.showToast(
|
this.platformUtilsService.showToast(
|
||||||
"error",
|
"error",
|
||||||
null,
|
null,
|
||||||
|
|
Loading…
Reference in New Issue