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 { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||||
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
|
||||||
import { OrganizationKeysRequest } from "@bitwarden/common/admin-console/models/request/organization-keys.request";
|
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 { ProductType } from "@bitwarden/common/enums";
|
||||||
import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
@ -121,7 +121,7 @@ export class PeopleComponent extends BasePeopleComponent<OrganizationUserView> {
|
||||||
private groupService: GroupService,
|
private groupService: GroupService,
|
||||||
private collectionService: CollectionService,
|
private collectionService: CollectionService,
|
||||||
organizationManagementPreferencesService: OrganizationManagementPreferencesService,
|
organizationManagementPreferencesService: OrganizationManagementPreferencesService,
|
||||||
private organizationBillingService: OrganizationBillingService,
|
private billingApiService: BillingApiServiceAbstraction,
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
apiService,
|
apiService,
|
||||||
|
@ -190,10 +190,11 @@ export class PeopleComponent extends BasePeopleComponent<OrganizationUserView> {
|
||||||
.find((p) => p.organizationId === this.organization.id);
|
.find((p) => p.organizationId === this.organization.id);
|
||||||
this.orgResetPasswordPolicyEnabled = resetPasswordPolicy?.enabled;
|
this.orgResetPasswordPolicyEnabled = resetPasswordPolicy?.enabled;
|
||||||
|
|
||||||
this.orgIsOnSecretsManagerStandalone =
|
const billingMetadata = await this.billingApiService.getOrganizationBillingMetadata(
|
||||||
await this.organizationBillingService.isOnSecretsManagerStandalone(
|
this.organization.id,
|
||||||
this.organization.id,
|
);
|
||||||
);
|
|
||||||
|
this.orgIsOnSecretsManagerStandalone = billingMetadata.isOnSecretsManagerStandalone;
|
||||||
|
|
||||||
await this.load();
|
await this.load();
|
||||||
|
|
||||||
|
|
|
@ -1058,7 +1058,6 @@ const safeProviders: SafeProvider[] = [
|
||||||
useClass: OrganizationBillingService,
|
useClass: OrganizationBillingService,
|
||||||
deps: [
|
deps: [
|
||||||
ApiServiceAbstraction,
|
ApiServiceAbstraction,
|
||||||
BillingApiServiceAbstraction,
|
|
||||||
CryptoServiceAbstraction,
|
CryptoServiceAbstraction,
|
||||||
EncryptService,
|
EncryptService,
|
||||||
I18nServiceAbstraction,
|
I18nServiceAbstraction,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { SubscriptionCancellationRequest } from "../../billing/models/request/subscription-cancellation.request";
|
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 { OrganizationBillingStatusResponse } from "../../billing/models/response/organization-billing-status.response";
|
||||||
import { OrganizationSubscriptionResponse } from "../../billing/models/response/organization-subscription.response";
|
import { OrganizationSubscriptionResponse } from "../../billing/models/response/organization-subscription.response";
|
||||||
import { PlanResponse } from "../../billing/models/response/plan.response";
|
import { PlanResponse } from "../../billing/models/response/plan.response";
|
||||||
|
@ -12,13 +13,15 @@ export abstract class BillingApiServiceAbstraction {
|
||||||
organizationId: string,
|
organizationId: string,
|
||||||
request: SubscriptionCancellationRequest,
|
request: SubscriptionCancellationRequest,
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
|
|
||||||
cancelPremiumUserSubscription: (request: SubscriptionCancellationRequest) => Promise<void>;
|
cancelPremiumUserSubscription: (request: SubscriptionCancellationRequest) => Promise<void>;
|
||||||
createClientOrganization: (
|
createClientOrganization: (
|
||||||
providerId: string,
|
providerId: string,
|
||||||
request: CreateClientOrganizationRequest,
|
request: CreateClientOrganizationRequest,
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
getBillingStatus: (id: string) => Promise<OrganizationBillingStatusResponse>;
|
getBillingStatus: (id: string) => Promise<OrganizationBillingStatusResponse>;
|
||||||
|
getOrganizationBillingMetadata: (
|
||||||
|
organizationId: string,
|
||||||
|
) => Promise<OrganizationBillingMetadataResponse>;
|
||||||
getOrganizationSubscription: (
|
getOrganizationSubscription: (
|
||||||
organizationId: string,
|
organizationId: string,
|
||||||
) => Promise<OrganizationSubscriptionResponse>;
|
) => Promise<OrganizationSubscriptionResponse>;
|
||||||
|
|
|
@ -41,8 +41,6 @@ export type SubscriptionInformation = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export abstract class OrganizationBillingServiceAbstraction {
|
export abstract class OrganizationBillingServiceAbstraction {
|
||||||
isOnSecretsManagerStandalone: (organizationId: string) => Promise<boolean>;
|
|
||||||
|
|
||||||
purchaseSubscription: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
|
purchaseSubscription: (subscription: SubscriptionInformation) => Promise<OrganizationResponse>;
|
||||||
|
|
||||||
startFree: (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 { ApiService } from "../../abstractions/api.service";
|
||||||
import { BillingApiServiceAbstraction } from "../../billing/abstractions/billilng-api.service.abstraction";
|
import { BillingApiServiceAbstraction } from "../../billing/abstractions/billilng-api.service.abstraction";
|
||||||
import { SubscriptionCancellationRequest } from "../../billing/models/request/subscription-cancellation.request";
|
import { SubscriptionCancellationRequest } from "../../billing/models/request/subscription-cancellation.request";
|
||||||
|
@ -53,6 +55,20 @@ export class BillingApiService implements BillingApiServiceAbstraction {
|
||||||
return new OrganizationBillingStatusResponse(r);
|
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(
|
async getOrganizationSubscription(
|
||||||
organizationId: string,
|
organizationId: string,
|
||||||
): Promise<OrganizationSubscriptionResponse> {
|
): Promise<OrganizationSubscriptionResponse> {
|
||||||
|
|
|
@ -9,7 +9,6 @@ import { I18nService } from "../../platform/abstractions/i18n.service";
|
||||||
import { EncString } from "../../platform/models/domain/enc-string";
|
import { EncString } from "../../platform/models/domain/enc-string";
|
||||||
import { OrgKey } from "../../types/key";
|
import { OrgKey } from "../../types/key";
|
||||||
import { SyncService } from "../../vault/abstractions/sync/sync.service.abstraction";
|
import { SyncService } from "../../vault/abstractions/sync/sync.service.abstraction";
|
||||||
import { BillingApiServiceAbstraction as BillingApiService } from "../abstractions/billilng-api.service.abstraction";
|
|
||||||
import {
|
import {
|
||||||
OrganizationBillingServiceAbstraction,
|
OrganizationBillingServiceAbstraction,
|
||||||
OrganizationInformation,
|
OrganizationInformation,
|
||||||
|
@ -29,7 +28,6 @@ interface OrganizationKeys {
|
||||||
export class OrganizationBillingService implements OrganizationBillingServiceAbstraction {
|
export class OrganizationBillingService implements OrganizationBillingServiceAbstraction {
|
||||||
constructor(
|
constructor(
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private billingApiService: BillingApiService,
|
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
private encryptService: EncryptService,
|
private encryptService: EncryptService,
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
|
@ -37,19 +35,6 @@ export class OrganizationBillingService implements OrganizationBillingServiceAbs
|
||||||
private syncService: SyncService,
|
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> {
|
async purchaseSubscription(subscription: SubscriptionInformation): Promise<OrganizationResponse> {
|
||||||
const request = new OrganizationCreateRequest();
|
const request = new OrganizationCreateRequest();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue