mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-31 17:57:43 +01: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:
parent
58f40b0085
commit
deabffb7b0
@ -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'));
|
||||
|
@ -3,6 +3,8 @@ import {
|
||||
OnInit,
|
||||
} from '@angular/core';
|
||||
|
||||
import { OrganizationUserStatusType } from '../../../enums/organizationUserStatusType';
|
||||
import { PolicyType } from '../../../enums/policyType';
|
||||
import { SendType } from '../../../enums/sendType';
|
||||
|
||||
import { SendView } from '../../../models/view/sendView';
|
||||
@ -10,8 +12,10 @@ import { SendView } from '../../../models/view/sendView';
|
||||
import { EnvironmentService } from '../../../abstractions/environment.service';
|
||||
import { I18nService } from '../../../abstractions/i18n.service';
|
||||
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
||||
import { PolicyService } from '../../../abstractions/policy.service';
|
||||
import { SearchService } from '../../../abstractions/search.service';
|
||||
import { SendService } from '../../../abstractions/send.service';
|
||||
import { UserService } from '../../../abstractions/user.service';
|
||||
|
||||
import { BroadcasterService } from '../../../angular/services/broadcaster.service';
|
||||
|
||||
@ -19,6 +23,7 @@ const BroadcasterSubscriptionId = 'SendComponent';
|
||||
|
||||
export class SendComponent implements OnInit {
|
||||
|
||||
disableSend = false;
|
||||
sendType = SendType;
|
||||
loaded = false;
|
||||
loading = true;
|
||||
@ -43,9 +48,20 @@ export class SendComponent implements OnInit {
|
||||
constructor(protected sendService: SendService, protected i18nService: I18nService,
|
||||
protected platformUtilsService: PlatformUtilsService, protected environmentService: EnvironmentService,
|
||||
protected broadcasterService: BroadcasterService, protected ngZone: NgZone,
|
||||
protected searchService: SearchService) { }
|
||||
protected searchService: SearchService, protected policyService: PolicyService,
|
||||
protected userService: UserService) { }
|
||||
|
||||
async ngOnInit() {
|
||||
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.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
||||
this.ngZone.run(async () => {
|
||||
switch (message.command) {
|
||||
@ -199,7 +215,7 @@ export class SendComponent implements OnInit {
|
||||
|
||||
private applyTextSearch() {
|
||||
if (this.searchText != null) {
|
||||
this.filteredSends = this.searchService.searchSends(this.filteredSends, this.searchText);
|
||||
this.filteredSends = this.searchService.searchSends(this.filteredSends, this.searchText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,5 @@ export enum PolicyType {
|
||||
SingleOrg = 3, // Allows users to only be apart of one organization
|
||||
RequireSso = 4, // Requires users to authenticate with SSO
|
||||
PersonalOwnership = 5, // Disables personal vault ownership for adding/cloning items
|
||||
DisableSend = 6, // Disables the ability to create and edit Bitwarden Sends
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user