mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 01:03:35 +00:00
Pm-10953/add-user-context-to-sync-replaces (#10627)
* 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>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
import { UserId } from "../../../types/guid";
|
||||
|
||||
export type BillingAccountProfile = {
|
||||
hasPremiumPersonally: boolean;
|
||||
hasPremiumFromAnyOrganization: boolean;
|
||||
@@ -32,5 +34,6 @@ export abstract class BillingAccountProfileStateService {
|
||||
abstract setHasPremium(
|
||||
hasPremiumPersonally: boolean,
|
||||
hasPremiumFromAnyOrganization: boolean,
|
||||
userId: UserId,
|
||||
): Promise<void>;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import { firstValueFrom } from "rxjs";
|
||||
import {
|
||||
FakeAccountService,
|
||||
mockAccountServiceWith,
|
||||
FakeActiveUserState,
|
||||
FakeStateProvider,
|
||||
FakeSingleUserState,
|
||||
} from "../../../../spec";
|
||||
@@ -18,7 +17,6 @@ import {
|
||||
describe("BillingAccountProfileStateService", () => {
|
||||
let stateProvider: FakeStateProvider;
|
||||
let sut: DefaultBillingAccountProfileStateService;
|
||||
let billingAccountProfileState: FakeActiveUserState<BillingAccountProfile>;
|
||||
let userBillingAccountProfileState: FakeSingleUserState<BillingAccountProfile>;
|
||||
let accountService: FakeAccountService;
|
||||
|
||||
@@ -30,10 +28,6 @@ describe("BillingAccountProfileStateService", () => {
|
||||
|
||||
sut = new DefaultBillingAccountProfileStateService(stateProvider);
|
||||
|
||||
billingAccountProfileState = stateProvider.activeUser.getFake(
|
||||
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
||||
);
|
||||
|
||||
userBillingAccountProfileState = stateProvider.singleUser.getFake(
|
||||
userId,
|
||||
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
||||
@@ -133,12 +127,11 @@ describe("BillingAccountProfileStateService", () => {
|
||||
|
||||
describe("setHasPremium", () => {
|
||||
it("should update the active users state when called", async () => {
|
||||
await sut.setHasPremium(true, false);
|
||||
await sut.setHasPremium(true, false, userId);
|
||||
|
||||
expect(billingAccountProfileState.nextMock).toHaveBeenCalledWith([
|
||||
userId,
|
||||
{ hasPremiumPersonally: true, hasPremiumFromAnyOrganization: false },
|
||||
]);
|
||||
expect(await firstValueFrom(sut.hasPremiumFromAnyOrganization$)).toBe(false);
|
||||
expect(await firstValueFrom(sut.hasPremiumPersonally$)).toBe(true);
|
||||
expect(await firstValueFrom(sut.hasPremiumFromAnySource$)).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
StateProvider,
|
||||
UserKeyDefinition,
|
||||
} from "../../../platform/state";
|
||||
import { UserId } from "../../../types/guid";
|
||||
import {
|
||||
BillingAccountProfile,
|
||||
BillingAccountProfileStateService,
|
||||
@@ -27,7 +28,7 @@ export class DefaultBillingAccountProfileStateService implements BillingAccountP
|
||||
hasPremiumPersonally$: Observable<boolean>;
|
||||
hasPremiumFromAnySource$: Observable<boolean>;
|
||||
|
||||
constructor(stateProvider: StateProvider) {
|
||||
constructor(private readonly stateProvider: StateProvider) {
|
||||
this.billingAccountProfileState = stateProvider.getActive(
|
||||
BILLING_ACCOUNT_PROFILE_KEY_DEFINITION,
|
||||
);
|
||||
@@ -62,8 +63,9 @@ export class DefaultBillingAccountProfileStateService implements BillingAccountP
|
||||
async setHasPremium(
|
||||
hasPremiumPersonally: boolean,
|
||||
hasPremiumFromAnyOrganization: boolean,
|
||||
userId: UserId,
|
||||
): Promise<void> {
|
||||
await this.billingAccountProfileState.update((billingAccountProfile) => {
|
||||
await this.stateProvider.getUser(userId, BILLING_ACCOUNT_PROFILE_KEY_DEFINITION).update((_) => {
|
||||
return {
|
||||
hasPremiumPersonally: hasPremiumPersonally,
|
||||
hasPremiumFromAnyOrganization: hasPremiumFromAnyOrganization,
|
||||
|
||||
Reference in New Issue
Block a user