mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-03 18:28:13 +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,
|
Output,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import { OrganizationUserStatusType } from '../../../enums/organizationUserStatusType';
|
||||||
|
import { PolicyType } from '../../../enums/policyType';
|
||||||
import { SendType } from '../../../enums/sendType';
|
import { SendType } from '../../../enums/sendType';
|
||||||
|
|
||||||
import { EnvironmentService } from '../../../abstractions/environment.service';
|
import { EnvironmentService } from '../../../abstractions/environment.service';
|
||||||
import { I18nService } from '../../../abstractions/i18n.service';
|
import { I18nService } from '../../../abstractions/i18n.service';
|
||||||
import { MessagingService } from '../../../abstractions/messaging.service';
|
import { MessagingService } from '../../../abstractions/messaging.service';
|
||||||
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
||||||
|
import { PolicyService } from '../../../abstractions/policy.service';
|
||||||
import { SendService } from '../../../abstractions/send.service';
|
import { SendService } from '../../../abstractions/send.service';
|
||||||
import { UserService } from '../../../abstractions/user.service';
|
import { UserService } from '../../../abstractions/user.service';
|
||||||
|
|
||||||
@ -30,6 +33,7 @@ export class AddEditComponent implements OnInit {
|
|||||||
@Output() onDeletedSend = new EventEmitter<SendView>();
|
@Output() onDeletedSend = new EventEmitter<SendView>();
|
||||||
@Output() onCancelled = new EventEmitter<SendView>();
|
@Output() onCancelled = new EventEmitter<SendView>();
|
||||||
|
|
||||||
|
disableSend = false;
|
||||||
editMode: boolean = false;
|
editMode: boolean = false;
|
||||||
send: SendView;
|
send: SendView;
|
||||||
link: string;
|
link: string;
|
||||||
@ -52,7 +56,7 @@ export class AddEditComponent implements OnInit {
|
|||||||
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
|
constructor(protected i18nService: I18nService, protected platformUtilsService: PlatformUtilsService,
|
||||||
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
|
protected environmentService: EnvironmentService, protected datePipe: DatePipe,
|
||||||
protected sendService: SendService, protected userService: UserService,
|
protected sendService: SendService, protected userService: UserService,
|
||||||
protected messagingService: MessagingService) {
|
protected messagingService: MessagingService, protected policyService: PolicyService) {
|
||||||
this.typeOptions = [
|
this.typeOptions = [
|
||||||
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
|
{ name: i18nService.t('sendTypeFile'), value: SendType.File },
|
||||||
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
|
{ name: i18nService.t('sendTypeText'), value: SendType.Text },
|
||||||
@ -84,6 +88,16 @@ export class AddEditComponent implements OnInit {
|
|||||||
this.title = this.i18nService.t('createSend');
|
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();
|
this.canAccessPremium = await this.userService.canAccessPremium();
|
||||||
if (!this.canAccessPremium) {
|
if (!this.canAccessPremium) {
|
||||||
this.type = SendType.Text;
|
this.type = SendType.Text;
|
||||||
@ -119,6 +133,12 @@ export class AddEditComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async submit(): Promise<boolean> {
|
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 === '') {
|
if (this.send.name == null || this.send.name === '') {
|
||||||
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'),
|
||||||
this.i18nService.t('nameRequired'));
|
this.i18nService.t('nameRequired'));
|
||||||
|
@ -3,6 +3,8 @@ import {
|
|||||||
OnInit,
|
OnInit,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
|
|
||||||
|
import { OrganizationUserStatusType } from '../../../enums/organizationUserStatusType';
|
||||||
|
import { PolicyType } from '../../../enums/policyType';
|
||||||
import { SendType } from '../../../enums/sendType';
|
import { SendType } from '../../../enums/sendType';
|
||||||
|
|
||||||
import { SendView } from '../../../models/view/sendView';
|
import { SendView } from '../../../models/view/sendView';
|
||||||
@ -10,8 +12,10 @@ import { SendView } from '../../../models/view/sendView';
|
|||||||
import { EnvironmentService } from '../../../abstractions/environment.service';
|
import { EnvironmentService } from '../../../abstractions/environment.service';
|
||||||
import { I18nService } from '../../../abstractions/i18n.service';
|
import { I18nService } from '../../../abstractions/i18n.service';
|
||||||
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
import { PlatformUtilsService } from '../../../abstractions/platformUtils.service';
|
||||||
|
import { PolicyService } from '../../../abstractions/policy.service';
|
||||||
import { SearchService } from '../../../abstractions/search.service';
|
import { SearchService } from '../../../abstractions/search.service';
|
||||||
import { SendService } from '../../../abstractions/send.service';
|
import { SendService } from '../../../abstractions/send.service';
|
||||||
|
import { UserService } from '../../../abstractions/user.service';
|
||||||
|
|
||||||
import { BroadcasterService } from '../../../angular/services/broadcaster.service';
|
import { BroadcasterService } from '../../../angular/services/broadcaster.service';
|
||||||
|
|
||||||
@ -19,6 +23,7 @@ const BroadcasterSubscriptionId = 'SendComponent';
|
|||||||
|
|
||||||
export class SendComponent implements OnInit {
|
export class SendComponent implements OnInit {
|
||||||
|
|
||||||
|
disableSend = false;
|
||||||
sendType = SendType;
|
sendType = SendType;
|
||||||
loaded = false;
|
loaded = false;
|
||||||
loading = true;
|
loading = true;
|
||||||
@ -43,9 +48,20 @@ export class SendComponent implements OnInit {
|
|||||||
constructor(protected sendService: SendService, protected i18nService: I18nService,
|
constructor(protected sendService: SendService, protected i18nService: I18nService,
|
||||||
protected platformUtilsService: PlatformUtilsService, protected environmentService: EnvironmentService,
|
protected platformUtilsService: PlatformUtilsService, protected environmentService: EnvironmentService,
|
||||||
protected broadcasterService: BroadcasterService, protected ngZone: NgZone,
|
protected broadcasterService: BroadcasterService, protected ngZone: NgZone,
|
||||||
protected searchService: SearchService) { }
|
protected searchService: SearchService, protected policyService: PolicyService,
|
||||||
|
protected userService: UserService) { }
|
||||||
|
|
||||||
async ngOnInit() {
|
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.broadcasterService.subscribe(BroadcasterSubscriptionId, (message: any) => {
|
||||||
this.ngZone.run(async () => {
|
this.ngZone.run(async () => {
|
||||||
switch (message.command) {
|
switch (message.command) {
|
||||||
@ -199,7 +215,7 @@ export class SendComponent implements OnInit {
|
|||||||
|
|
||||||
private applyTextSearch() {
|
private applyTextSearch() {
|
||||||
if (this.searchText != null) {
|
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
|
SingleOrg = 3, // Allows users to only be apart of one organization
|
||||||
RequireSso = 4, // Requires users to authenticate with SSO
|
RequireSso = 4, // Requires users to authenticate with SSO
|
||||||
PersonalOwnership = 5, // Disables personal vault ownership for adding/cloning items
|
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