mirror of
https://github.com/bitwarden/browser
synced 2025-12-30 23:23:52 +00:00
* Require userId for setting masterKeyEncryptedUserKey * Replace folders for specified user * Require userId for collection replace * Cipher Replace requires userId * Require UserId to update equivalent domains * Require userId for policy replace * sync state updates between fake state for better testing * Revert to public observable tests Since they now sync, we can test single-user updates impacting active user observables * Do not init fake states through sync Do not sync initial null values, that might wipe out already existing data. * Require userId for Send replace * Include userId for organization replace * Require userId for billing sync data * Require user Id for key connector sync data * Allow decode of token by userId * Require userId for synced key connector updates * Add userId to policy setting during organization invite accept * Fix cli * Handle null userId --------- Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
49 lines
2.1 KiB
TypeScript
49 lines
2.1 KiB
TypeScript
import { Observable, firstValueFrom } from "rxjs";
|
|
|
|
import { ActiveUserState, CombinedState, StateProvider } from "../../../platform/state";
|
|
import { UserId } from "../../../types/guid";
|
|
import { SendData } from "../models/data/send.data";
|
|
import { SendView } from "../models/view/send.view";
|
|
|
|
import { SEND_USER_DECRYPTED, SEND_USER_ENCRYPTED } from "./key-definitions";
|
|
import { SendStateProvider as SendStateProviderAbstraction } from "./send-state.provider.abstraction";
|
|
|
|
/** State provider for sends */
|
|
export class SendStateProvider implements SendStateProviderAbstraction {
|
|
/** Observable for the encrypted sends for an active user */
|
|
encryptedState$: Observable<CombinedState<Record<string, SendData>>>;
|
|
/** Observable with the decrypted sends for an active user */
|
|
decryptedState$: Observable<SendView[]>;
|
|
|
|
private activeUserEncryptedState: ActiveUserState<Record<string, SendData>>;
|
|
private activeUserDecryptedState: ActiveUserState<SendView[]>;
|
|
|
|
constructor(protected stateProvider: StateProvider) {
|
|
this.activeUserEncryptedState = this.stateProvider.getActive(SEND_USER_ENCRYPTED);
|
|
this.encryptedState$ = this.activeUserEncryptedState.combinedState$;
|
|
|
|
this.activeUserDecryptedState = this.stateProvider.getActive(SEND_USER_DECRYPTED);
|
|
this.decryptedState$ = this.activeUserDecryptedState.state$;
|
|
}
|
|
|
|
/** Gets the encrypted sends from state for an active user */
|
|
async getEncryptedSends(): Promise<CombinedState<{ [id: string]: SendData }>> {
|
|
return await firstValueFrom(this.encryptedState$);
|
|
}
|
|
|
|
/** Sets the encrypted send state for an active user */
|
|
async setEncryptedSends(value: { [id: string]: SendData }, userId: UserId): Promise<void> {
|
|
await this.stateProvider.getUser(userId, SEND_USER_ENCRYPTED).update(() => value);
|
|
}
|
|
|
|
/** Gets the decrypted sends from state for the active user */
|
|
async getDecryptedSends(): Promise<SendView[]> {
|
|
return await firstValueFrom(this.decryptedState$);
|
|
}
|
|
|
|
/** Sets the decrypted send state for an active user */
|
|
async setDecryptedSends(value: SendView[]): Promise<void> {
|
|
await this.activeUserDecryptedState.update(() => value);
|
|
}
|
|
}
|