mirror of
https://github.com/bitwarden/jslib
synced 2025-12-06 00:03:29 +00:00
Merge branch 'master' of https://github.com/bitwarden/jslib into feature/refactor-folder-example
# Conflicts: # common/spec/domain/folder.spec.ts # common/src/models/data/folderData.ts # common/src/services/folder.service.ts # common/src/services/sync.service.ts
This commit is contained in:
@@ -61,7 +61,6 @@ export class UpdatePasswordComponent extends BaseChangePasswordComponent {
|
||||
|
||||
async cancel() {
|
||||
await this.stateService.setOrganizationInvitation(null);
|
||||
await this.stateService.setLoginRedirect(null);
|
||||
this.router.navigate(["/vault"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ export class AuthGuardService implements CanActivate {
|
||||
async canActivate(route: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) {
|
||||
const isAuthed = await this.stateService.getIsAuthenticated();
|
||||
if (!isAuthed) {
|
||||
this.messagingService.send("authBlocked");
|
||||
this.messagingService.send("authBlocked", { url: routerState.url });
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -28,16 +28,14 @@ export class AuthGuardService implements CanActivate {
|
||||
if (routerState != null) {
|
||||
this.messagingService.send("lockedUrl", { url: routerState.url });
|
||||
}
|
||||
this.router.navigate(["lock"], { queryParams: { promptBiometric: true } });
|
||||
return false;
|
||||
return this.router.createUrlTree(["lock"], { queryParams: { promptBiometric: true } });
|
||||
}
|
||||
|
||||
if (
|
||||
!routerState.url.includes("remove-password") &&
|
||||
(await this.keyConnectorService.getConvertAccountRequired())
|
||||
) {
|
||||
this.router.navigate(["/remove-password"]);
|
||||
return false;
|
||||
return this.router.createUrlTree(["/remove-password"]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -18,11 +18,9 @@ export class UnauthGuardService implements CanActivate {
|
||||
if (isAuthed) {
|
||||
const locked = await this.vaultTimeoutService.isLocked();
|
||||
if (locked) {
|
||||
this.router.navigate(["lock"]);
|
||||
} else {
|
||||
this.router.navigate([this.homepage]);
|
||||
return this.router.createUrlTree(["lock"]);
|
||||
}
|
||||
return false;
|
||||
return this.router.createUrlTree([this.homepage]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -242,8 +242,6 @@ export abstract class StateService<T extends Account = Account> {
|
||||
setLocalData: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
getLocale: (options?: StorageOptions) => Promise<string>;
|
||||
setLocale: (value: string, options?: StorageOptions) => Promise<void>;
|
||||
getLoginRedirect: (options?: StorageOptions) => Promise<any>;
|
||||
setLoginRedirect: (value: any, options?: StorageOptions) => Promise<void>;
|
||||
getMainWindowSize: (options?: StorageOptions) => Promise<number>;
|
||||
setMainWindowSize: (value: number, options?: StorageOptions) => Promise<void>;
|
||||
getMinimizeOnCopyToClipboard: (options?: StorageOptions) => Promise<boolean>;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1633,19 +1633,6 @@ export class StateService<
|
||||
);
|
||||
}
|
||||
|
||||
async getLoginRedirect(options?: StorageOptions): Promise<any> {
|
||||
return (await this.getGlobals(this.reconcileOptions(options, this.defaultInMemoryOptions)))
|
||||
?.loginRedirect;
|
||||
}
|
||||
|
||||
async setLoginRedirect(value: any, options?: StorageOptions): Promise<void> {
|
||||
const globals = await this.getGlobals(
|
||||
this.reconcileOptions(options, this.defaultInMemoryOptions)
|
||||
);
|
||||
globals.loginRedirect = value;
|
||||
await this.saveGlobals(globals, this.reconcileOptions(options, this.defaultInMemoryOptions));
|
||||
}
|
||||
|
||||
async getMainWindowSize(options?: StorageOptions): Promise<number> {
|
||||
return (await this.getGlobals(this.reconcileOptions(options, this.defaultInMemoryOptions)))
|
||||
?.mainWindowSize;
|
||||
|
||||
@@ -95,7 +95,6 @@ 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();
|
||||
@@ -103,8 +102,8 @@ export class SyncService implements SyncServiceAbstraction {
|
||||
await this.syncProfile(response.profile);
|
||||
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);
|
||||
|
||||
@@ -199,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);
|
||||
}
|
||||
@@ -237,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);
|
||||
}
|
||||
@@ -354,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user