From b3d34e86fd33c4714f2e30a6893b59b90bd5ec27 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 23 Nov 2017 22:33:08 -0500 Subject: [PATCH] preserve collection ids on save --- src/models/data/cipherData.ts | 9 +++++++-- src/services/cipher.service.ts | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/models/data/cipherData.ts b/src/models/data/cipherData.ts index be5a0d8ee7..413612122f 100644 --- a/src/models/data/cipherData.ts +++ b/src/models/data/cipherData.ts @@ -30,7 +30,7 @@ class CipherData { attachments?: AttachmentData[]; collectionIds?: string[]; - constructor(response: CipherResponse, userId: string) { + constructor(response: CipherResponse, userId: string, collectionIds?: string[]) { this.id = response.id; this.organizationId = response.organizationId; this.folderId = response.folderId; @@ -40,7 +40,12 @@ class CipherData { this.favorite = response.favorite; this.revisionDate = response.revisionDate; this.type = response.type; - this.collectionIds = response.collectionIds; + + if (collectionIds != null) { + this.collectionIds = collectionIds; + } else { + this.collectionIds = response.collectionIds; + } this.name = response.data.Name; this.notes = response.data.Notes; diff --git a/src/services/cipher.service.ts b/src/services/cipher.service.ts index 3441a83f83..69650cf113 100644 --- a/src/services/cipher.service.ts +++ b/src/services/cipher.service.ts @@ -82,6 +82,7 @@ export default class CipherService { cipher.favorite = model.favorite; cipher.organizationId = model.organizationId; cipher.type = model.type; + cipher.collectionIds = model.collectionIds; const key = await this.cryptoService.getOrgKey(cipher.organizationId); await Promise.all([ @@ -295,7 +296,7 @@ export default class CipherService { } const userId = await this.userService.getUserId(); - const data = new CipherData(response, userId); + const data = new CipherData(response, userId, cipher.collectionIds); await this.upsert(data); } @@ -324,7 +325,7 @@ export default class CipherService { } const userId = await self.userService.getUserId(); - const data = new CipherData(response, userId); + const data = new CipherData(response, userId, cipher.collectionIds); this.upsert(data); resolve(new Cipher(data));