From a24c41ff2504b39e09a7744b072f25a564392582 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 22 Oct 2018 16:46:48 -0400 Subject: [PATCH] set org id and collections if filtered --- jslib | 2 +- .../organizations/vault/add-edit.component.ts | 8 -------- .../organizations/vault/vault.component.html | 4 ++-- src/app/organizations/vault/vault.component.ts | 18 ++++++++++-------- src/app/vault/vault.component.ts | 9 ++++++++- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/jslib b/jslib index 3021afc9dd..0a36a211c3 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 3021afc9ddae1579f2226010ee487fa3edcddb0b +Subproject commit 0a36a211c355ada433ce9b0560c5ab85a6cead23 diff --git a/src/app/organizations/vault/add-edit.component.ts b/src/app/organizations/vault/add-edit.component.ts index a8c2a1b4e5..0460566da9 100644 --- a/src/app/organizations/vault/add-edit.component.ts +++ b/src/app/organizations/vault/add-edit.component.ts @@ -40,14 +40,6 @@ export class AddEditComponent extends BaseAddEditComponent { userService, collectionService, totpService, passwordGenerationService, messagingService); } - async load() { - await super.load(); - if (!this.editMode) { - this.cipher.organizationId = this.organization.id; - } - await this.organizationChanged(); - } - protected loadCollections() { if (!this.organization.isAdmin) { return super.loadCollections(); diff --git a/src/app/organizations/vault/vault.component.html b/src/app/organizations/vault/vault.component.html index fce03d428d..ecc138fbf4 100644 --- a/src/app/organizations/vault/vault.component.html +++ b/src/app/organizations/vault/vault.component.html @@ -13,12 +13,12 @@ - + (onCollectionsClicked)="editCipherCollections($event)" (onEventsClicked)="viewEvents($event)"> diff --git a/src/app/organizations/vault/vault.component.ts b/src/app/organizations/vault/vault.component.ts index a64b27c93d..1aca5b5e6a 100644 --- a/src/app/organizations/vault/vault.component.ts +++ b/src/app/organizations/vault/vault.component.ts @@ -52,7 +52,6 @@ export class VaultComponent implements OnInit, OnDestroy { organization: Organization; collectionId: string; type: CipherType; - showAdd = true; private modal: ModalComponent = null; @@ -66,7 +65,6 @@ export class VaultComponent implements OnInit, OnDestroy { ngOnInit() { this.route.parent.params.subscribe(async (params) => { this.organization = await this.userService.getOrganization(params.organizationId); - this.showAdd = this.organization.isAdmin; this.groupingsComponent.organization = this.organization; this.ciphersComponent.organization = this.organization; @@ -124,7 +122,7 @@ export class VaultComponent implements OnInit, OnDestroy { } async clearGroupingFilters() { - this.ciphersComponent.showAddNew = this.showAdd; + this.ciphersComponent.showAddNew = true; this.groupingsComponent.searchPlaceholder = this.i18nService.t('searchVault'); await this.ciphersComponent.applyFilter(); this.clearFilters(); @@ -132,7 +130,7 @@ export class VaultComponent implements OnInit, OnDestroy { } async filterCipherType(type: CipherType, load = false) { - this.ciphersComponent.showAddNew = this.showAdd; + this.ciphersComponent.showAddNew = true; this.groupingsComponent.searchPlaceholder = this.i18nService.t('searchType'); const filter = (c: CipherView) => c.type === type; if (load) { @@ -146,7 +144,7 @@ export class VaultComponent implements OnInit, OnDestroy { } async filterCollection(collectionId: string, load = false) { - this.ciphersComponent.showAddNew = false; + this.ciphersComponent.showAddNew = true; this.groupingsComponent.searchPlaceholder = this.i18nService.t('searchCollection'); const filter = (c: CipherView) => { if (collectionId === 'unassigned') { @@ -226,7 +224,14 @@ export class VaultComponent implements OnInit, OnDestroy { addCipher() { const component = this.editCipher(null); + component.organizationId = this.organization.id; component.type = this.type; + if (this.organization.isAdmin) { + component.collections = this.groupingsComponent.collections.filter((c) => !c.readOnly); + } + if (this.collectionId != null) { + component.collectionIds = [this.collectionId]; + } } editCipher(cipher: CipherView) { @@ -238,9 +243,6 @@ export class VaultComponent implements OnInit, OnDestroy { this.modal = this.cipherAddEditModalRef.createComponent(factory).instance; const childComponent = this.modal.show(AddEditComponent, this.cipherAddEditModalRef); - if (this.organization.isAdmin) { - childComponent.collections = this.groupingsComponent.collections.filter((c) => !c.readOnly); - } childComponent.organization = this.organization; childComponent.cipherId = cipher == null ? null : cipher.id; childComponent.onSavedCipher.subscribe(async (c: CipherView) => { diff --git a/src/app/vault/vault.component.ts b/src/app/vault/vault.component.ts index 741b120e41..9f146abee5 100644 --- a/src/app/vault/vault.component.ts +++ b/src/app/vault/vault.component.ts @@ -187,7 +187,7 @@ export class VaultComponent implements OnInit, OnDestroy { } async filterCollection(collectionId: string) { - this.ciphersComponent.showAddNew = false; + this.ciphersComponent.showAddNew = true; this.groupingsComponent.searchPlaceholder = this.i18nService.t('searchCollection'); await this.ciphersComponent.load((c) => c.collectionIds != null && c.collectionIds.indexOf(collectionId) > -1); this.clearFilters(); @@ -327,6 +327,13 @@ export class VaultComponent implements OnInit, OnDestroy { const component = this.editCipher(null); component.type = this.type; component.folderId = this.folderId === 'none' ? null : this.folderId; + if (this.collectionId != null) { + const collection = this.groupingsComponent.collections.filter((c) => c.id === this.collectionId); + if (collection.length > 0) { + component.organizationId = collection[0].organizationId; + component.collectionIds = [this.collectionId]; + } + } } editCipher(cipher: CipherView) {