From 00f1aad65ea2e243713d409873dfb5d833296897 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 26 Jun 2019 17:43:03 -0400 Subject: [PATCH] dont allow select no collections --- src/angular/components/collections.component.ts | 8 +++++++- src/angular/components/share.component.ts | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/angular/components/collections.component.ts b/src/angular/components/collections.component.ts index 379f5b5747..abd17fafad 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 4c656a5b13..3903709b08 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'));