diff --git a/common/spec/domain/cipher.spec.ts b/common/spec/domain/cipher.spec.ts index 0e6ed45237..0eff1b85d8 100644 --- a/common/spec/domain/cipher.spec.ts +++ b/common/spec/domain/cipher.spec.ts @@ -24,7 +24,6 @@ describe("Cipher DTO", () => { expect(cipher).toEqual({ id: null, - userId: null, organizationId: null, folderId: null, name: null, @@ -53,7 +52,6 @@ describe("Cipher DTO", () => { id: "id", organizationId: "orgId", folderId: "folderId", - userId: "userId", edit: true, viewPassword: true, organizationUseTotp: true, @@ -115,7 +113,6 @@ describe("Cipher DTO", () => { expect(cipher).toEqual({ id: "id", - userId: "userId", organizationId: "orgId", folderId: "folderId", name: { encryptedString: "EncryptedString", encryptionType: 0 }, @@ -181,7 +178,7 @@ describe("Cipher DTO", () => { it("toCipherData", () => { const cipher = new Cipher(cipherData); - expect(cipher.toCipherData("userId")).toEqual(cipherData); + expect(cipher.toCipherData()).toEqual(cipherData); }); it("Decrypt", async () => { @@ -242,7 +239,6 @@ describe("Cipher DTO", () => { id: "id", organizationId: "orgId", folderId: "folderId", - userId: "userId", edit: true, viewPassword: true, organizationUseTotp: true, @@ -264,7 +260,6 @@ describe("Cipher DTO", () => { expect(cipher).toEqual({ id: "id", - userId: "userId", organizationId: "orgId", folderId: "folderId", name: { encryptedString: "EncryptedString", encryptionType: 0 }, @@ -288,7 +283,7 @@ describe("Cipher DTO", () => { it("toCipherData", () => { const cipher = new Cipher(cipherData); - expect(cipher.toCipherData("userId")).toEqual(cipherData); + expect(cipher.toCipherData()).toEqual(cipherData); }); it("Decrypt", async () => { @@ -343,7 +338,6 @@ describe("Cipher DTO", () => { id: "id", organizationId: "orgId", folderId: "folderId", - userId: "userId", edit: true, viewPassword: true, organizationUseTotp: true, @@ -370,7 +364,6 @@ describe("Cipher DTO", () => { expect(cipher).toEqual({ id: "id", - userId: "userId", organizationId: "orgId", folderId: "folderId", name: { encryptedString: "EncryptedString", encryptionType: 0 }, @@ -401,7 +394,7 @@ describe("Cipher DTO", () => { it("toCipherData", () => { const cipher = new Cipher(cipherData); - expect(cipher.toCipherData("userId")).toEqual(cipherData); + expect(cipher.toCipherData()).toEqual(cipherData); }); it("Decrypt", async () => { @@ -462,7 +455,6 @@ describe("Cipher DTO", () => { id: "id", organizationId: "orgId", folderId: "folderId", - userId: "userId", edit: true, viewPassword: true, organizationUseTotp: true, @@ -501,7 +493,6 @@ describe("Cipher DTO", () => { expect(cipher).toEqual({ id: "id", - userId: "userId", organizationId: "orgId", folderId: "folderId", name: { encryptedString: "EncryptedString", encryptionType: 0 }, @@ -544,7 +535,7 @@ describe("Cipher DTO", () => { it("toCipherData", () => { const cipher = new Cipher(cipherData); - expect(cipher.toCipherData("userId")).toEqual(cipherData); + expect(cipher.toCipherData()).toEqual(cipherData); }); it("Decrypt", async () => { diff --git a/common/spec/domain/folder.spec.ts b/common/spec/domain/folder.spec.ts index 64ee40b994..20ca6b9523 100644 --- a/common/spec/domain/folder.spec.ts +++ b/common/spec/domain/folder.spec.ts @@ -9,7 +9,6 @@ describe("Folder", () => { beforeEach(() => { data = { id: "id", - userId: "userId", name: "encName", revisionDate: "2022-01-31T12:00:00.000Z", }; diff --git a/common/spec/domain/send.spec.ts b/common/spec/domain/send.spec.ts index d63c622ad9..c97f1be64e 100644 --- a/common/spec/domain/send.spec.ts +++ b/common/spec/domain/send.spec.ts @@ -17,7 +17,6 @@ describe("Send", () => { data = { id: "id", accessId: "accessId", - userId: "userId", type: SendType.Text, name: "encName", notes: "encNotes", @@ -45,7 +44,6 @@ describe("Send", () => { expect(send).toEqual({ id: null, accessId: null, - userId: null, type: undefined, name: null, notes: null, @@ -69,7 +67,6 @@ describe("Send", () => { expect(send).toEqual({ id: "id", accessId: "accessId", - userId: "userId", type: SendType.Text, name: { encryptedString: "encName", encryptionType: 0 }, notes: { encryptedString: "encNotes", encryptionType: 0 }, @@ -96,7 +93,6 @@ describe("Send", () => { const send = new Send(); send.id = "id"; send.accessId = "accessId"; - send.userId = "userId"; send.type = SendType.Text; send.name = mockEnc("name"); send.notes = mockEnc("notes"); diff --git a/common/src/models/data/cipherData.ts b/common/src/models/data/cipherData.ts index 7ebc7070a9..aa82a5fd0b 100644 --- a/common/src/models/data/cipherData.ts +++ b/common/src/models/data/cipherData.ts @@ -14,7 +14,6 @@ export class CipherData { id: string; organizationId: string; folderId: string; - userId: string; edit: boolean; viewPassword: boolean; organizationUseTotp: boolean; @@ -34,7 +33,7 @@ export class CipherData { deletedDate: string; reprompt: CipherRepromptType; - constructor(response?: CipherResponse, userId?: string, collectionIds?: string[]) { + constructor(response?: CipherResponse, collectionIds?: string[]) { if (response == null) { return; } @@ -42,7 +41,6 @@ export class CipherData { this.id = response.id; this.organizationId = response.organizationId; this.folderId = response.folderId; - this.userId = userId; this.edit = response.edit; this.viewPassword = response.viewPassword; this.organizationUseTotp = response.organizationUseTotp; diff --git a/common/src/models/data/folderData.ts b/common/src/models/data/folderData.ts index 459ba4de38..76f1e5d724 100644 --- a/common/src/models/data/folderData.ts +++ b/common/src/models/data/folderData.ts @@ -2,12 +2,10 @@ import { FolderResponse } from "../response/folderResponse"; export class FolderData { id: string; - userId: string; name: string; revisionDate: string; - constructor(response: FolderResponse, userId: string) { - this.userId = userId; + constructor(response: FolderResponse) { this.name = response.name; this.id = response.id; this.revisionDate = response.revisionDate; diff --git a/common/src/models/data/sendData.ts b/common/src/models/data/sendData.ts index 18c007e36d..4c3bb8b2ff 100644 --- a/common/src/models/data/sendData.ts +++ b/common/src/models/data/sendData.ts @@ -7,7 +7,6 @@ import { SendTextData } from "./sendTextData"; export class SendData { id: string; accessId: string; - userId: string; type: SendType; name: string; notes: string; @@ -23,14 +22,13 @@ export class SendData { disabled: boolean; hideEmail: boolean; - constructor(response?: SendResponse, userId?: string) { + constructor(response?: SendResponse) { if (response == null) { return; } this.id = response.id; this.accessId = response.accessId; - this.userId = userId; this.type = response.type; this.name = response.name; this.notes = response.notes; diff --git a/common/src/models/domain/cipher.ts b/common/src/models/domain/cipher.ts index 23f98686fe..b25be35520 100644 --- a/common/src/models/domain/cipher.ts +++ b/common/src/models/domain/cipher.ts @@ -49,13 +49,12 @@ export class Cipher extends Domain { obj, { id: null, - userId: null, organizationId: null, folderId: null, name: null, notes: null, }, - ["id", "userId", "organizationId", "folderId"] + ["id", "organizationId", "folderId"] ); this.type = obj.type; @@ -186,12 +185,11 @@ export class Cipher extends Domain { return model; } - toCipherData(userId: string): CipherData { + toCipherData(): CipherData { const c = new CipherData(); c.id = this.id; c.organizationId = this.organizationId; c.folderId = this.folderId; - c.userId = this.organizationId != null ? userId : null; c.edit = this.edit; c.viewPassword = this.viewPassword; c.organizationUseTotp = this.organizationUseTotp; diff --git a/common/src/models/domain/send.ts b/common/src/models/domain/send.ts index c2e769ece5..a398ac2dbf 100644 --- a/common/src/models/domain/send.ts +++ b/common/src/models/domain/send.ts @@ -12,7 +12,6 @@ import { SendText } from "./sendText"; export class Send extends Domain { id: string; accessId: string; - userId: string; type: SendType; name: EncString; notes: EncString; @@ -40,12 +39,11 @@ export class Send extends Domain { { id: null, accessId: null, - userId: null, name: null, notes: null, key: null, }, - ["id", "accessId", "userId"] + ["id", "accessId"] ); this.type = obj.type; diff --git a/common/src/services/cipher.service.ts b/common/src/services/cipher.service.ts index 1deeec8eae..7482828f67 100644 --- a/common/src/services/cipher.service.ts +++ b/common/src/services/cipher.service.ts @@ -605,11 +605,7 @@ export class CipherService implements CipherServiceAbstraction { response = await this.apiService.putCipher(cipher.id, request); } - const data = new CipherData( - response, - await this.stateService.getUserId(), - cipher.collectionIds - ); + const data = new CipherData(response, cipher.collectionIds); await this.upsert(data); } @@ -635,7 +631,7 @@ export class CipherService implements CipherServiceAbstraction { const encCipher = await this.encrypt(cipher); const request = new CipherShareRequest(encCipher); const response = await this.apiService.putShareCipher(cipher.id, request); - const data = new CipherData(response, await this.stateService.getUserId(), collectionIds); + const data = new CipherData(response, collectionIds); await this.upsert(data); } @@ -666,8 +662,7 @@ export class CipherService implements CipherServiceAbstraction { } throw e; } - const userId = await this.stateService.getUserId(); - await this.upsert(encCiphers.map((c) => c.toCipherData(userId))); + await this.upsert(encCiphers.map((c) => c.toCipherData())); } saveAttachmentWithServer(cipher: Cipher, unencryptedFile: any, admin = false): Promise { @@ -741,11 +736,7 @@ export class CipherService implements CipherServiceAbstraction { } } - const cData = new CipherData( - response, - await this.stateService.getUserId(), - cipher.collectionIds - ); + const cData = new CipherData(response, cipher.collectionIds); if (!admin) { await this.upsert(cData); } @@ -801,7 +792,7 @@ export class CipherService implements CipherServiceAbstraction { async saveCollectionsWithServer(cipher: Cipher): Promise { const request = new CipherCollectionsRequest(cipher.collectionIds); await this.apiService.putCipherCollections(cipher.id, request); - const data = cipher.toCipherData(await this.stateService.getUserId()); + const data = cipher.toCipherData(); await this.upsert(data); } diff --git a/common/src/services/folder.service.ts b/common/src/services/folder.service.ts index 666ca6d2b8..47db0cb735 100644 --- a/common/src/services/folder.service.ts +++ b/common/src/services/folder.service.ts @@ -117,8 +117,7 @@ export class FolderService implements FolderServiceAbstraction { response = await this.apiService.putFolder(folder.id, request); } - const userId = await this.stateService.getUserId(); - const data = new FolderData(response, userId); + const data = new FolderData(response); await this.upsert(data); } diff --git a/common/src/services/send.service.ts b/common/src/services/send.service.ts index 75530db34b..3d8daa3a69 100644 --- a/common/src/services/send.service.ts +++ b/common/src/services/send.service.ts @@ -166,8 +166,7 @@ export class SendService implements SendServiceAbstraction { response = await this.apiService.putSend(sendData[0].id, request); } - const userId = await this.stateService.getUserId(); - const data = new SendData(response, userId); + const data = new SendData(response); await this.upsert(data); } @@ -257,8 +256,7 @@ export class SendService implements SendServiceAbstraction { async removePasswordWithServer(id: string): Promise { const response = await this.apiService.putSendRemovePassword(id); - const userId = await this.stateService.getUserId(); - const data = new SendData(response, userId); + const data = new SendData(response); await this.upsert(data); } diff --git a/common/src/services/sync.service.ts b/common/src/services/sync.service.ts index 93611238bc..177d76f5da 100644 --- a/common/src/services/sync.service.ts +++ b/common/src/services/sync.service.ts @@ -95,16 +95,15 @@ export class SyncService implements SyncServiceAbstraction { return this.syncCompleted(false); } - const userId = await this.stateService.getUserId(); try { await this.apiService.refreshIdentityToken(); const response = await this.apiService.getSync(); await this.syncProfile(response.profile); - await this.syncFolders(userId, response.folders); + await this.syncFolders(response.folders); await this.syncCollections(response.collections); - await this.syncCiphers(userId, response.ciphers); - await this.syncSends(userId, response.sends); + await this.syncCiphers(response.ciphers); + await this.syncSends(response.sends); await this.syncSettings(response.domains); await this.syncPolicies(response.policies); @@ -130,8 +129,7 @@ export class SyncService implements SyncServiceAbstraction { ) { const remoteFolder = await this.apiService.getFolder(notification.id); if (remoteFolder != null) { - const userId = await this.stateService.getUserId(); - await this.folderService.upsert(new FolderData(remoteFolder, userId)); + await this.folderService.upsert(new FolderData(remoteFolder)); this.messagingService.send("syncedUpsertedFolder", { folderId: notification.id }); return this.syncCompleted(true); } @@ -200,8 +198,7 @@ export class SyncService implements SyncServiceAbstraction { if (shouldUpdate) { const remoteCipher = await this.apiService.getCipher(notification.id); if (remoteCipher != null) { - const userId = await this.stateService.getUserId(); - await this.cipherService.upsert(new CipherData(remoteCipher, userId)); + await this.cipherService.upsert(new CipherData(remoteCipher)); this.messagingService.send("syncedUpsertedCipher", { cipherId: notification.id }); return this.syncCompleted(true); } @@ -238,8 +235,7 @@ export class SyncService implements SyncServiceAbstraction { ) { const remoteSend = await this.apiService.getSend(notification.id); if (remoteSend != null) { - const userId = await this.stateService.getUserId(); - await this.sendService.upsert(new SendData(remoteSend, userId)); + await this.sendService.upsert(new SendData(remoteSend)); this.messagingService.send("syncedUpsertedSend", { sendId: notification.id }); return this.syncCompleted(true); } @@ -339,10 +335,10 @@ export class SyncService implements SyncServiceAbstraction { } } - private async syncFolders(userId: string, response: FolderResponse[]) { + private async syncFolders(response: FolderResponse[]) { const folders: { [id: string]: FolderData } = {}; response.forEach((f) => { - folders[f.id] = new FolderData(f, userId); + folders[f.id] = new FolderData(f); }); return await this.folderService.replace(folders); } @@ -355,18 +351,18 @@ export class SyncService implements SyncServiceAbstraction { return await this.collectionService.replace(collections); } - private async syncCiphers(userId: string, response: CipherResponse[]) { + private async syncCiphers(response: CipherResponse[]) { const ciphers: { [id: string]: CipherData } = {}; response.forEach((c) => { - ciphers[c.id] = new CipherData(c, userId); + ciphers[c.id] = new CipherData(c); }); return await this.cipherService.replace(ciphers); } - private async syncSends(userId: string, response: SendResponse[]) { + private async syncSends(response: SendResponse[]) { const sends: { [id: string]: SendData } = {}; response.forEach((s) => { - sends[s.id] = new SendData(s, userId); + sends[s.id] = new SendData(); }); return await this.sendService.replace(sends); }