1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

pm-5273 Update references

This commit is contained in:
Carlos Gonçalves
2024-03-09 09:53:14 +00:00
parent b6b7ea283c
commit 1145201549
16 changed files with 54 additions and 45 deletions

View File

@@ -19,6 +19,7 @@ import {
UsernameGeneratorOptions,
} from "@bitwarden/common/tools/generator/username";
import { EmailForwarderOptions } from "@bitwarden/common/tools/models/domain/email-forwarder-options";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
@Directive()
export class GeneratorComponent implements OnInit {
@@ -57,6 +58,7 @@ export class GeneratorComponent implements OnInit {
protected usernameGenerationService: UsernameGenerationServiceAbstraction,
protected platformUtilsService: PlatformUtilsService,
protected stateService: StateService,
protected cipherService: CipherService,
protected i18nService: I18nService,
protected logService: LogService,
protected route: ActivatedRoute,

View File

@@ -678,7 +678,7 @@ export class AddEditComponent implements OnInit, OnDestroy {
}
async loadAddEditCipherInfo(): Promise<boolean> {
const addEditCipherInfo: any = await this.stateService.getAddEditCipherInfo();
const addEditCipherInfo: any = await this.cipherService.getAddEditCipherInfo();
const loadedSavedInfo = addEditCipherInfo != null;
if (loadedSavedInfo) {
@@ -691,7 +691,7 @@ export class AddEditComponent implements OnInit, OnDestroy {
}
}
await this.stateService.setAddEditCipherInfo(null);
await this.cipherService.setAddEditCipherInfo(null);
return loadedSavedInfo;
}

View File

@@ -20,7 +20,6 @@ import { UriMatchType } from "../../vault/enums";
import { CipherData } from "../../vault/models/data/cipher.data";
import { LocalData } from "../../vault/models/data/local.data";
import { CipherView } from "../../vault/models/view/cipher.view";
import { AddEditCipherInfo } from "../../vault/types/add-edit-cipher-info";
import { KdfType, ThemeType } from "../enums";
import { ServerConfigData } from "../models/data/server-config.data";
import {
@@ -61,8 +60,6 @@ export abstract class StateService<T extends Account = Account> {
getAccessToken: (options?: StorageOptions) => Promise<string>;
setAccessToken: (value: string, options?: StorageOptions) => Promise<void>;
getAddEditCipherInfo: (options?: StorageOptions) => Promise<AddEditCipherInfo>;
setAddEditCipherInfo: (value: AddEditCipherInfo, options?: StorageOptions) => Promise<void>;
getAlwaysShowDock: (options?: StorageOptions) => Promise<boolean>;
setAlwaysShowDock: (value: boolean, options?: StorageOptions) => Promise<void>;
getApiKeyClientId: (options?: StorageOptions) => Promise<string>;

View File

@@ -24,7 +24,6 @@ import { UriMatchType } from "../../vault/enums";
import { CipherData } from "../../vault/models/data/cipher.data";
import { LocalData } from "../../vault/models/data/local.data";
import { CipherView } from "../../vault/models/view/cipher.view";
import { AddEditCipherInfo } from "../../vault/types/add-edit-cipher-info";
import { EnvironmentService } from "../abstractions/environment.service";
import { LogService } from "../abstractions/log.service";
import {
@@ -271,34 +270,6 @@ export class StateService<
await this.saveAccount(account, options);
}
async getAddEditCipherInfo(options?: StorageOptions): Promise<AddEditCipherInfo> {
const account = await this.getAccount(
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
// ensure prototype on cipher
const raw = account?.data?.addEditCipherInfo;
return raw == null
? null
: {
cipher:
raw?.cipher.toJSON != null
? raw.cipher
: CipherView.fromJSON(raw?.cipher as Jsonify<CipherView>),
collectionIds: raw?.collectionIds,
};
}
async setAddEditCipherInfo(value: AddEditCipherInfo, options?: StorageOptions): Promise<void> {
const account = await this.getAccount(
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
account.data.addEditCipherInfo = value;
await this.saveAccount(
account,
this.reconcileOptions(options, await this.defaultInMemoryOptions()),
);
}
async getAlwaysShowDock(options?: StorageOptions): Promise<boolean> {
return (
(await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskOptions())))

View File

@@ -6,6 +6,7 @@ import { Cipher } from "../models/domain/cipher";
import { Field } from "../models/domain/field";
import { CipherView } from "../models/view/cipher.view";
import { FieldView } from "../models/view/field.view";
import { AddEditCipherInfo } from "../types/add-edit-cipher-info";
export abstract class CipherService {
clearCache: (userId?: string) => Promise<void>;
@@ -89,4 +90,6 @@ export abstract class CipherService {
) => Promise<void>;
getKeyForCipherKeyDecryption: (cipher: Cipher) => Promise<any>;
decryptCiphers: (ciphers: Cipher[]) => Promise<CipherView[]>;
getAddEditCipherInfo: () => Promise<AddEditCipherInfo>;
setAddEditCipherInfo: (value: AddEditCipherInfo) => Promise<void>;
}

View File

@@ -59,6 +59,7 @@ import { AttachmentView } from "../models/view/attachment.view";
import { CipherView } from "../models/view/cipher.view";
import { FieldView } from "../models/view/field.view";
import { PasswordHistoryView } from "../models/view/password-history.view";
import { AddEditCipherInfo } from "../types/add-edit-cipher-info";
import { DECRYPTED_CIPHERS, ENCRYPTED_CIPHERS } from "./key-state/ciphers.state";
@@ -68,6 +69,12 @@ const CIPHERS_DISK_KEY = new KeyDefinition<Record<string, LocalData>>(CIPHERS_DI
deserializer: (obj) => obj,
});
const ADD_EDIT_CIPHER_INFO_KEY = new KeyDefinition<AddEditCipherInfo>(
CIPHERS_DISK,
"addEditCipherInfo",
{ deserializer: (obj) => obj },
);
export class CipherService implements CipherServiceAbstraction {
private sortedCiphersCache: SortedCiphersCache = new SortedCiphersCache(
this.sortCiphersByLastUsed,
@@ -76,10 +83,12 @@ export class CipherService implements CipherServiceAbstraction {
localData$: Observable<Record<string, LocalData>>;
ciphers$: Observable<Record<string, CipherData>>;
cipherViews$: Observable<CipherView[]>;
addEditCipherInfo$: Observable<AddEditCipherInfo>;
private localDataState: ActiveUserState<Record<string, LocalData>>;
private encryptedCiphersState: ActiveUserState<Record<string, CipherData>>;
private decryptedCiphersState: DerivedState<CipherView[]>;
private addEditCipherInfoState: ActiveUserState<AddEditCipherInfo>;
constructor(
private cryptoService: CryptoService,
@@ -101,10 +110,12 @@ export class CipherService implements CipherServiceAbstraction {
DECRYPTED_CIPHERS,
{ cipherService: this },
);
this.addEditCipherInfoState = this.stateProvider.getActive(ADD_EDIT_CIPHER_INFO_KEY);
this.localData$ = this.localDataState.state$;
this.ciphers$ = this.encryptedCiphersState.state$;
this.cipherViews$ = this.decryptedCiphersState.state$;
this.addEditCipherInfo$ = this.addEditCipherInfoState.state$;
}
async getDecryptedCipherCache(): Promise<CipherView[]> {
@@ -1045,6 +1056,15 @@ export class CipherService implements CipherServiceAbstraction {
);
}
async getAddEditCipherInfo(): Promise<AddEditCipherInfo> {
const info = await firstValueFrom(this.addEditCipherInfo$);
return info;
}
async setAddEditCipherInfo(value: AddEditCipherInfo) {
await this.addEditCipherInfoState.update(() => value);
}
// Helpers
// In the case of a cipher that is being shared with an organization, we want to decrypt the