1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[PM-14366] Deprecated active user state from billing state service (#12273)

* Updated billing state provider to not rely on ActiveUserStateProvider

* Updated usages

* Resolved browser build

* Resolved web build

* Resolved CLI build

* resolved desktop build

* Update apps/cli/src/tools/send/commands/create.command.ts

Co-authored-by:  Audrey  <ajensen@bitwarden.com>

* Move subscription visibility logic from component to service

* Resolved unit test failures. Using existing userIds where present

* Simplified activeUserId access

* Resolved typescript strict errors

* Resolved broken unit test

* Resolved ts strict error

---------

Co-authored-by:  Audrey  <ajensen@bitwarden.com>
This commit is contained in:
Conner Turnbull
2025-01-07 10:25:26 -05:00
committed by GitHub
parent 003f5fdae9
commit 91d6963074
56 changed files with 595 additions and 227 deletions

View File

@@ -262,8 +262,9 @@ export class GetCommand extends DownloadCommand {
return Response.error("Couldn't generate TOTP code.");
}
const account = await firstValueFrom(this.accountService.activeAccount$);
const canAccessPremium = await firstValueFrom(
this.accountProfileService.hasPremiumFromAnySource$,
this.accountProfileService.hasPremiumFromAnySource$(account.id),
);
if (!canAccessPremium) {
const originalCipher = await this.cipherService.get(cipher.id);
@@ -347,8 +348,9 @@ export class GetCommand extends DownloadCommand {
return Response.multipleResults(attachments.map((a) => a.id));
}
const account = await firstValueFrom(this.accountService.activeAccount$);
const canAccessPremium = await firstValueFrom(
this.accountProfileService.hasPremiumFromAnySource$,
this.accountProfileService.hasPremiumFromAnySource$(account.id),
);
if (!canAccessPremium) {
const originalCipher = await this.cipherService.get(cipher.id);

View File

@@ -149,6 +149,7 @@ export class OssServeConfigurator {
this.serviceContainer.environmentService,
this.serviceContainer.sendApiService,
this.serviceContainer.billingAccountProfileStateService,
this.serviceContainer.accountService,
);
this.sendDeleteCommand = new SendDeleteCommand(
this.serviceContainer.sendService,
@@ -166,6 +167,7 @@ export class OssServeConfigurator {
this.sendGetCommand,
this.serviceContainer.sendApiService,
this.serviceContainer.billingAccountProfileStateService,
this.serviceContainer.accountService,
);
this.sendListCommand = new SendListCommand(
this.serviceContainer.sendService,

View File

@@ -597,6 +597,8 @@ export class ServiceContainer {
this.billingAccountProfileStateService = new DefaultBillingAccountProfileStateService(
this.stateProvider,
this.platformUtilsService,
this.apiService,
);
this.taskSchedulerService = new DefaultTaskSchedulerService(this.logService);

View File

@@ -3,8 +3,9 @@
import * as fs from "fs";
import * as path from "path";
import { firstValueFrom } from "rxjs";
import { firstValueFrom, switchMap } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
@@ -23,6 +24,7 @@ export class SendCreateCommand {
private environmentService: EnvironmentService,
private sendApiService: SendApiService,
private accountProfileService: BillingAccountProfileStateService,
private accountService: AccountService,
) {}
async run(requestJson: any, cmdOptions: Record<string, any>) {
@@ -78,6 +80,10 @@ export class SendCreateCommand {
req.key = null;
req.maxAccessCount = maxAccessCount;
const hasPremium$ = this.accountService.activeAccount$.pipe(
switchMap(({ id }) => this.accountProfileService.hasPremiumFromAnySource$(id)),
);
switch (req.type) {
case SendType.File:
if (process.env.BW_SERVE === "true") {
@@ -86,7 +92,7 @@ export class SendCreateCommand {
);
}
if (!(await firstValueFrom(this.accountProfileService.hasPremiumFromAnySource$))) {
if (!(await firstValueFrom(hasPremium$))) {
return Response.error("Premium status is required to use this feature.");
}

View File

@@ -2,6 +2,7 @@
// @ts-strict-ignore
import { firstValueFrom } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
import { SendType } from "@bitwarden/common/tools/send/enums/send-type";
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
@@ -19,6 +20,7 @@ export class SendEditCommand {
private getCommand: SendGetCommand,
private sendApiService: SendApiService,
private accountProfileService: BillingAccountProfileStateService,
private accountService: AccountService,
) {}
async run(requestJson: string, cmdOptions: Record<string, any>): Promise<Response> {
@@ -61,8 +63,9 @@ export class SendEditCommand {
return Response.badRequest("Cannot change a Send's type");
}
const account = await firstValueFrom(this.accountService.activeAccount$);
const canAccessPremium = await firstValueFrom(
this.accountProfileService.hasPremiumFromAnySource$,
this.accountProfileService.hasPremiumFromAnySource$(account.id),
);
if (send.type === SendType.File && !canAccessPremium) {
return Response.error("Premium status is required to use this feature.");

View File

@@ -258,6 +258,7 @@ export class SendProgram extends BaseProgram {
getCmd,
this.serviceContainer.sendApiService,
this.serviceContainer.billingAccountProfileStateService,
this.serviceContainer.accountService,
);
const response = await cmd.run(encodedJson, options);
this.processResponse(response);
@@ -331,6 +332,7 @@ export class SendProgram extends BaseProgram {
this.serviceContainer.environmentService,
this.serviceContainer.sendApiService,
this.serviceContainer.billingAccountProfileStateService,
this.serviceContainer.accountService,
);
return await cmd.run(encodedJson, options);
}

View File

@@ -136,10 +136,13 @@ export class CreateCommand {
return Response.notFound();
}
if (
cipher.organizationId == null &&
!(await firstValueFrom(this.accountProfileService.hasPremiumFromAnySource$))
) {
const activeUserId = await firstValueFrom(this.activeUserId$);
const canAccessPremium = await firstValueFrom(
this.accountProfileService.hasPremiumFromAnySource$(activeUserId),
);
if (cipher.organizationId == null && !canAccessPremium) {
return Response.error("Premium status is required to use this feature.");
}
@@ -152,7 +155,6 @@ export class CreateCommand {
}
try {
const activeUserId = await firstValueFrom(this.activeUserId$);
const updatedCipher = await this.cipherService.saveAttachmentRawWithServer(
cipher,
fileName,

View File

@@ -89,8 +89,9 @@ export class DeleteCommand {
return Response.error("Attachment `" + id + "` was not found.");
}
const account = await firstValueFrom(this.accountService.activeAccount$);
const canAccessPremium = await firstValueFrom(
this.accountProfileService.hasPremiumFromAnySource$,
this.accountProfileService.hasPremiumFromAnySource$(account.id),
);
if (cipher.organizationId == null && !canAccessPremium) {
return Response.error("Premium status is required to use this feature.");