diff --git a/src/angular/components/collections.component.ts b/src/angular/components/collections.component.ts index 379f5b5747a..abd17fafad1 100644 --- a/src/angular/components/collections.component.ts +++ b/src/angular/components/collections.component.ts @@ -17,6 +17,7 @@ import { Cipher } from '../../models/domain/cipher'; export class CollectionsComponent implements OnInit { @Input() cipherId: string; + @Input() allowSelectNone = false; @Output() onSavedCollections = new EventEmitter(); formPromise: Promise; @@ -48,9 +49,14 @@ export class CollectionsComponent implements OnInit { } async submit() { - this.cipherDomain.collectionIds = this.collections + const selectedCollectionIds = this.collections .filter((c) => !!(c as any).checked) .map((c) => c.id); + if (!this.allowSelectNone && selectedCollectionIds.length === 0) { + this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), + this.i18nService.t('selectOneCollection')); + } + this.cipherDomain.collectionIds = selectedCollectionIds; try { this.formPromise = this.saveCollections(); await this.formPromise; diff --git a/src/angular/components/share.component.ts b/src/angular/components/share.component.ts index 4c656a5b138..3903709b08e 100644 --- a/src/angular/components/share.component.ts +++ b/src/angular/components/share.component.ts @@ -64,13 +64,20 @@ export class ShareComponent implements OnInit { } async submit(): Promise { + const selectedCollectionIds = this.collections + .filter((c) => !!(c as any).checked) + .map((c) => c.id); + if (selectedCollectionIds.length === 0) { + this.platformUtilsService.showToast('error', this.i18nService.t('errorOccurred'), + this.i18nService.t('selectOneCollection')); + } + const cipherDomain = await this.cipherService.get(this.cipherId); const cipherView = await cipherDomain.decrypt(); - const checkedCollectionIds = this.collections.filter((c) => (c as any).checked).map((c) => c.id); try { this.formPromise = this.cipherService.shareWithServer(cipherView, this.organizationId, - checkedCollectionIds).then(async () => { + selectedCollectionIds).then(async () => { this.onSharedCipher.emit(); this.platformUtilsService.eventTrack('Shared Cipher'); this.platformUtilsService.showToast('success', null, this.i18nService.t('sharedItem'));