Remove userId from data models (#771)

This commit is contained in:
Oscar Hinton 2022-04-20 15:59:51 +02:00 committed by GitHub
parent f6e3481fe9
commit 366d9b3c63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 30 additions and 70 deletions

View File

@ -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 () => {

View File

@ -9,7 +9,6 @@ describe("Folder", () => {
beforeEach(() => {
data = {
id: "id",
userId: "userId",
name: "encName",
revisionDate: "2022-01-31T12:00:00.000Z",
};

View File

@ -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");

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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<Cipher> {
@ -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<any> {
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);
}

View File

@ -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);
}

View File

@ -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<any> {
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);
}

View File

@ -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);
}