Use new endpoint to determine SM standalone (#8904)
This commit is contained in:
parent
e89c82defe
commit
a8ba48898b
|
@ -37,7 +37,7 @@ import {
|
|||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||
import { OrganizationKeysRequest } from "@bitwarden/common/admin-console/models/request/organization-keys.request";
|
||||
import { OrganizationBillingServiceAbstraction as OrganizationBillingService } from "@bitwarden/common/billing/abstractions/organization-billing.service";
|
||||
import { BillingApiServiceAbstraction } from "@bitwarden/common/billing/abstractions/billilng-api.service.abstraction";
|
||||
import { ProductType } from "@bitwarden/common/enums";
|
||||
import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||
|
@ -121,7 +121,7 @@ export class PeopleComponent extends BasePeopleComponent<OrganizationUserView> {
|
|||
private groupService: GroupService,
|
||||
private collectionService: CollectionService,
|
||||
organizationManagementPreferencesService: OrganizationManagementPreferencesService,
|
||||
private organizationBillingService: OrganizationBillingService,
|
||||
private billingApiService: BillingApiServiceAbstraction,
|
||||
) {
|
||||
super(
|
||||
apiService,
|
||||
|
@ -190,10 +190,11 @@ export class PeopleComponent extends BasePeopleComponent<OrganizationUserView> {
|
|||
.find((p) => p.organizationId === this.organization.id);
|
||||
this.orgResetPasswordPolicyEnabled = resetPasswordPolicy?.enabled;
|
||||
|
||||
this.orgIsOnSecretsManagerStandalone =
|
||||
await this.organizationBillingService.isOnSecretsManagerStandalone(
|
||||
this.organization.id,
|
||||
);
|
||||
const billingMetadata = await this.billingApiService.getOrganizationBillingMetadata(
|
||||
this.organization.id,
|
||||
);
|
||||
|
||||
this.orgIsOnSecretsManagerStandalone = billingMetadata.isOnSecretsManagerStandalone;
|
||||
|
||||
await this.load();
|
||||
|
||||
|
|
|
@ -1058,7 +1058,6 @@ const safeProviders: SafeProvider[] = [
|
|||
useClass: OrganizationBillingService,
|
||||
deps: [
|
||||
ApiServiceAbstraction,
|
||||
BillingApiServiceAbstraction,
|
||||
CryptoServiceAbstraction,
|
||||
EncryptService,
|
||||
I18nServiceAbstraction,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { SubscriptionCancellationRequest } from "../../billing/models/request/subscription-cancellation.request";
|
||||
import { OrganizationBillingMetadataResponse } from "../../billing/models/response/organization-billing-metadata.response";
|
||||
import { OrganizationBillingStatusResponse } from "../../billing/models/response/organization-billing-status.response";
|
||||
import { OrganizationSubscriptionResponse } from "../../billing/models/response/organization-subscription.response";
|
||||
import { PlanResponse } from "../../billing/models/response/plan.response";
|
||||
|
@ -12,13 +13,15 @@ export abstract class BillingApiServiceAbstraction {
|
|||
organizationId: string,
|
||||
request: SubscriptionCancellationRequest,
|
||||
) => Promise<void>;
|
||||
|
||||
cancelPremiumUserSubscription: (request: SubscriptionCancellationRequest) => Promise<void>;
|
||||
createClientOrganization: (
|
||||
providerId: string,
|
||||
request: CreateClientOrganizationRequest,
|
||||
) => Promise<void>;
|
||||
getBillingStatus: (id: string) => Promise<OrganizationBillingStatusResponse>;
|
||||
getOrganizationBillingMetadata: (
|
||||
organizationId: string,
|
||||
) => Promise<OrganizationBillingMetadataResponse>;
|
||||
getOrganizationSubscription: (
|
||||
organizationId: string,
|
||||
) => Promise<OrganizationSubscriptionResponse>;
|
||||
|
|
|
@ -41,8 +41,6 @@ export type SubscriptionInformation = {
|
|||
};
|
||||
|
||||
export abstract class OrganizationBillingServiceAbstraction {
|
||||
isOnSecretsManagerStandalone: (organizationId: string) => Promise<boolean>;
|
||||
|
||||
purchaseSubscription: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
|
||||
|
||||
startFree: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import { BaseResponse } from "../../../models/response/base.response";
|
||||
|
||||
export class OrganizationBillingMetadataResponse extends BaseResponse {
|
||||
isOnSecretsManagerStandalone: boolean;
|
||||
|
||||
constructor(response: any) {
|
||||
super(response);
|
||||
this.isOnSecretsManagerStandalone = this.getResponseProperty("IsOnSecretsManagerStandalone");
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
import { OrganizationBillingMetadataResponse } from "@bitwarden/common/billing/models/response/organization-billing-metadata.response";
|
||||
|
||||
import { ApiService } from "../../abstractions/api.service";
|
||||
import { BillingApiServiceAbstraction } from "../../billing/abstractions/billilng-api.service.abstraction";
|
||||
import { SubscriptionCancellationRequest } from "../../billing/models/request/subscription-cancellation.request";
|
||||
|
@ -53,6 +55,20 @@ export class BillingApiService implements BillingApiServiceAbstraction {
|
|||
return new OrganizationBillingStatusResponse(r);
|
||||
}
|
||||
|
||||
async getOrganizationBillingMetadata(
|
||||
organizationId: string,
|
||||
): Promise<OrganizationBillingMetadataResponse> {
|
||||
const r = await this.apiService.send(
|
||||
"GET",
|
||||
"/organizations/" + organizationId + "/billing/metadata",
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
);
|
||||
|
||||
return new OrganizationBillingMetadataResponse(r);
|
||||
}
|
||||
|
||||
async getOrganizationSubscription(
|
||||
organizationId: string,
|
||||
): Promise<OrganizationSubscriptionResponse> {
|
||||
|
|
|
@ -9,7 +9,6 @@ import { I18nService } from "../../platform/abstractions/i18n.service";
|
|||
import { EncString } from "../../platform/models/domain/enc-string";
|
||||
import { OrgKey } from "../../types/key";
|
||||
import { SyncService } from "../../vault/abstractions/sync/sync.service.abstraction";
|
||||
import { BillingApiServiceAbstraction as BillingApiService } from "../abstractions/billilng-api.service.abstraction";
|
||||
import {
|
||||
OrganizationBillingServiceAbstraction,
|
||||
OrganizationInformation,
|
||||
|
@ -29,7 +28,6 @@ interface OrganizationKeys {
|
|||
export class OrganizationBillingService implements OrganizationBillingServiceAbstraction {
|
||||
constructor(
|
||||
private apiService: ApiService,
|
||||
private billingApiService: BillingApiService,
|
||||
private cryptoService: CryptoService,
|
||||
private encryptService: EncryptService,
|
||||
private i18nService: I18nService,
|
||||
|
@ -37,19 +35,6 @@ export class OrganizationBillingService implements OrganizationBillingServiceAbs
|
|||
private syncService: SyncService,
|
||||
) {}
|
||||
|
||||
async isOnSecretsManagerStandalone(organizationId: string): Promise<boolean> {
|
||||
const response = await this.billingApiService.getOrganizationSubscription(organizationId);
|
||||
if (response.customerDiscount?.id === "sm-standalone") {
|
||||
const productIds = response.subscription.items.map((item) => item.productId);
|
||||
return (
|
||||
response.customerDiscount?.appliesTo.filter((appliesToProductId) =>
|
||||
productIds.includes(appliesToProductId),
|
||||
).length > 0
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async purchaseSubscription(subscription: SubscriptionInformation): Promise<OrganizationResponse> {
|
||||
const request = new OrganizationCreateRequest();
|
||||
|
||||
|
|
Loading…
Reference in New Issue