1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 11:43:46 +00:00

[AC-1104] Fix access import/export with custom permission (#5014)

* [AC-1104] Allow importBlockedByPolicy to be overridden

Adjust the import component so that the importBlockedByPolicy flag can be overridden by the org import component to always return false.

* [AC-1104] Allow disabledByPolicy to be overridden in export component

Adjust the export component so that the disabledByPolicy flag can be overridden by the org export component to always return false.

* [AC-1104] Cleanup logic that disables export form

* [AC-1104] Use observable subscription for assigning importBlockedByPolicy flag

* [AC-1264] Add optional success callback for import component

Use the optional callback in org-import.component.ts to clear the file and file contents when the user does not have access to the vault page

* [AC-1264] Re-order properties

* [AC-1104] Refactor import component to only use onSuccess callback that can be overridden
This commit is contained in:
Shane Melton
2023-05-30 16:30:15 -07:00
committed by GitHub
parent 2f44b9b0dd
commit e092d42b72
4 changed files with 79 additions and 39 deletions

View File

@@ -1,7 +1,8 @@
import { Component, OnInit } from "@angular/core";
import { Component, OnDestroy, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import * as JSZip from "jszip";
import { firstValueFrom } from "rxjs";
import { Subject } from "rxjs";
import { takeUntil } from "rxjs/operators";
import Swal, { SweetAlertIcon } from "sweetalert2";
import { DialogServiceAbstraction } from "@bitwarden/angular/services/dialog";
@@ -14,28 +15,29 @@ import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { SyncService } from "@bitwarden/common/vault/abstractions/sync/sync.service.abstraction";
import {
ImportOption,
ImportType,
ImportResult,
ImportServiceAbstraction,
ImportType,
} from "@bitwarden/importer";
import { ImportSuccessDialogComponent, FilePasswordPromptComponent } from "./dialog";
import { FilePasswordPromptComponent, ImportSuccessDialogComponent } from "./dialog";
@Component({
selector: "app-import",
templateUrl: "import.component.html",
})
export class ImportComponent implements OnInit {
export class ImportComponent implements OnInit, OnDestroy {
featuredImportOptions: ImportOption[];
importOptions: ImportOption[];
format: ImportType = null;
fileContents: string;
fileSelected: File;
loading = false;
importBlockedByPolicy = false;
protected organizationId: string = null;
protected successNavigate: any[] = ["vault"];
protected destroy$ = new Subject<void>();
private _importBlockedByPolicy = false;
constructor(
protected i18nService: I18nService,
@@ -49,12 +51,26 @@ export class ImportComponent implements OnInit {
protected dialogService: DialogServiceAbstraction
) {}
async ngOnInit() {
protected get importBlockedByPolicy(): boolean {
return this._importBlockedByPolicy;
}
/**
* Callback that is called after a successful import.
*/
protected async onSuccessfulImport(): Promise<void> {
await this.router.navigate(["vault"]);
}
ngOnInit() {
this.setImportOptions();
this.importBlockedByPolicy = await firstValueFrom(
this.policyService.policyAppliesToActiveUser$(PolicyType.PersonalOwnership)
);
this.policyService
.policyAppliesToActiveUser$(PolicyType.PersonalOwnership)
.pipe(takeUntil(this.destroy$))
.subscribe((policyAppliesToActiveUser) => {
this._importBlockedByPolicy = policyAppliesToActiveUser;
});
}
async submit() {
@@ -134,7 +150,7 @@ export class ImportComponent implements OnInit {
});
this.syncService.fullSync(true);
this.router.navigate(this.successNavigate);
await this.onSuccessfulImport();
} catch (e) {
this.error(e);
this.logService.error(e);
@@ -264,4 +280,9 @@ export class ImportComponent implements OnInit {
return await ref.onClosedPromise();
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
}