diff --git a/src/angular/components/send/add-edit.component.ts b/src/angular/components/send/add-edit.component.ts index fb90fa97621..c764cce88a3 100644 --- a/src/angular/components/send/add-edit.component.ts +++ b/src/angular/components/send/add-edit.component.ts @@ -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(); @Output() onCancelled = new EventEmitter(); + 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 { + 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')); diff --git a/src/angular/components/send/send.component.ts b/src/angular/components/send/send.component.ts index 674e9622f61..ee521f1120d 100644 --- a/src/angular/components/send/send.component.ts +++ b/src/angular/components/send/send.component.ts @@ -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); } } } diff --git a/src/enums/policyType.ts b/src/enums/policyType.ts index a01fa7df477..8ed07c9d77b 100644 --- a/src/enums/policyType.ts +++ b/src/enums/policyType.ts @@ -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 }