mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-21 11:35:34 +01:00
[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";
|
||||
}
|
||||
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user