Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Disable Private Vault Export Policy (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Sep 14, 2021
1 parent a85c45a commit ee1ea92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
22 changes: 19 additions & 3 deletions angular/src/components/export.component.ts
@@ -1,6 +1,7 @@
import {
Directive,
EventEmitter,
OnInit,
Output,
} from '@angular/core';

Expand All @@ -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<string>;
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'));
Expand Down
1 change: 1 addition & 0 deletions common/src/enums/policyType.ts
Expand Up @@ -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
}

0 comments on commit ee1ea92

Please sign in to comment.