From ee1ea922a9d5a51ef8df2abf4b97fc035ed782be Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Tue, 14 Sep 2021 16:32:06 +0200 Subject: [PATCH] Disable Private Vault Export Policy (#482) --- angular/src/components/export.component.ts | 22 +++++++++++++++++++--- common/src/enums/policyType.ts | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/angular/src/components/export.component.ts b/angular/src/components/export.component.ts index 2f82d7e38..e492942d7 100644 --- a/angular/src/components/export.component.ts +++ b/angular/src/components/export.component.ts @@ -1,6 +1,7 @@ import { Directive, EventEmitter, + OnInit, Output, } from '@angular/core'; @@ -9,28 +10,43 @@ import { EventService } from 'jslib-common/abstractions/event.service'; import { ExportService } from 'jslib-common/abstractions/export.service'; import { I18nService } from 'jslib-common/abstractions/i18n.service'; import { PlatformUtilsService } from 'jslib-common/abstractions/platformUtils.service'; +import { PolicyService } from 'jslib-common/abstractions/policy.service'; import { EventType } from 'jslib-common/enums/eventType'; -import { HashPurpose } from 'jslib-common/enums/hashPurpose'; +import { PolicyType } from 'jslib-common/enums/policyType'; @Directive() -export class ExportComponent { +export class ExportComponent implements OnInit { @Output() onSaved = new EventEmitter(); formPromise: Promise; masterPassword: string; format: 'json' | 'encrypted_json' | 'csv' = 'json'; showPassword = false; + disabledByPolicy: boolean = false; constructor(protected cryptoService: CryptoService, protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService, protected exportService: ExportService, - protected eventService: EventService, protected win: Window) { } + protected eventService: EventService, private policyService: PolicyService, protected win: Window) { } + + async ngOnInit() { + await this.checkExportDisabled(); + } + + async checkExportDisabled() { + this.disabledByPolicy = await this.policyService.policyAppliesToUser(PolicyType.DisablePersonalVaultExport); + } get encryptedFormat() { return this.format === 'encrypted_json'; } async submit() { + if (this.disabledByPolicy) { + this.platformUtilsService.showToast('error', null, this.i18nService.t('personalVaultExportPolicyInEffect')); + return; + } + if (this.masterPassword == null || this.masterPassword === '') { this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), this.i18nService.t('invalidMasterPassword')); diff --git a/common/src/enums/policyType.ts b/common/src/enums/policyType.ts index 9af8cebd9..244ed4a17 100644 --- a/common/src/enums/policyType.ts +++ b/common/src/enums/policyType.ts @@ -9,4 +9,5 @@ export enum PolicyType { SendOptions = 7, // Sets restrictions or defaults for Bitwarden Sends ResetPassword = 8, // Allows orgs to use reset password : also can enable auto-enrollment during invite flow MaximumVaultTimeout = 9, // Sets the maximum allowed vault timeout + DisablePersonalVaultExport = 10, // Disable personal vault export }