1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

Implement disable send policy (#259)

* Implement disable send policy

* Linter fixes

* Add toast on submit if sends are disabled
This commit is contained in:
Matt Gibson
2021-02-04 11:22:31 -06:00
committed by GitHub
parent 58f40b0085
commit deabffb7b0
3 changed files with 40 additions and 3 deletions

View File

@@ -7,12 +7,15 @@ import {
Output,
} from '@angular/core';
import { OrganizationUserStatusType } from '../../../enums/organizationUserStatusType';
import { PolicyType } from '../../../enums/policyType';
import { SendType } from '../../../enums/sendType';
import { EnvironmentService } from '../../../abstractions/environment.service';
import { I18nService } from '../../../abstractions/i18n.service';
import { MessagingService } from '../../../abstractions/messaging.service';
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
import { PolicyService } from '../../../abstractions/policy.service';
import { SendService } from '../../../abstractions/send.service';
import { UserService } from '../../../abstractions/user.service';
@@ -30,6 +33,7 @@ export class AddEditComponent implements OnInit {
@Output() onDeletedSend = new EventEmitter<SendView>();
@Output() onCancelled = new EventEmitter<SendView>();
disableSend = false;
editMode: boolean = false;
send: SendView;
link: string;
@@ -52,7 +56,7 @@ export class AddEditComponent implements OnInit {
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
protected sendService: SendService, protected userService: UserService,
protected messagingService: MessagingService) {
protected messagingService: MessagingService, protected policyService: PolicyService) {
this.typeOptions = [
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
@@ -84,6 +88,16 @@ export class AddEditComponent implements OnInit {
this.title = this.i18nService.t('createSend');
}
const policies = await this.policyService.getAll(PolicyType.DisableSend);
const organizations = await this.userService.getAllOrganizations();
this.disableSend = organizations.some(o => {
return o.enabled &&
o.status === OrganizationUserStatusType.Confirmed &&
o.usePolicies &&
!o.canManagePolicies &&
policies.some(p => p.organizationId === o.id && p.enabled);
});
this.canAccessPremium = await this.userService.canAccessPremium();
if (!this.canAccessPremium) {
this.type = SendType.Text;
@@ -119,6 +133,12 @@ export class AddEditComponent implements OnInit {
}
async submit(): Promise<boolean> {
if (this.disableSend) {
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('sendDisabledWarning'));
return false;
}
if (this.send.name == null || this.send.name === '') {
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
this.i18nService.t('nameRequired'));