Patch subscription plan frontend validation

This commit is contained in:
Tuan Dang
2023-06-12 17:47:32 +01:00
parent 342ee50063
commit 98efffafaa
6 changed files with 44 additions and 33 deletions

View File

@@ -95,6 +95,13 @@ class EELicenseService {
return this.globalFeatureSet; return this.globalFeatureSet;
} }
public async refreshOrganizationPlan(organizationId: string) {
if (this.instanceType === 'cloud') {
this.localFeatureSet.del(organizationId);
await this.getOrganizationPlan(organizationId);
}
}
public async initGlobalFeatureSet() { public async initGlobalFeatureSet() {
const licenseServerKey = await getLicenseServerKey(); const licenseServerKey = await getLicenseServerKey();

View File

@@ -153,22 +153,24 @@ export const updateSubscriptionOrgQuantity = async ({
EELicenseService.localFeatureSet.del(organizationId); EELicenseService.localFeatureSet.del(organizationId);
} }
if (EELicenseService.instanceType === 'enterprise-self-hosted') {
// instance of Infisical is an enterprise self-hosted instance
const usedSeats = await MembershipOrg.countDocuments({
status: ACCEPTED
});
await licenseKeyRequest.patch(
`${await getLicenseServerUrl()}/api/license/v1/license`,
{
usedSeats
}
);
}
} }
if (EELicenseService.instanceType === 'enterprise-self-hosted') {
// instance of Infisical is an enterprise self-hosted instance
const usedSeats = await MembershipOrg.countDocuments({
status: ACCEPTED
});
await licenseKeyRequest.patch(
`${await getLicenseServerUrl()}/api/license/v1/license`,
{
usedSeats
}
);
}
await EELicenseService.refreshOrganizationPlan(organizationId);
return stripeSubscription; return stripeSubscription;
}; };

View File

@@ -6,6 +6,7 @@ import {
Secret Secret
} from '../models'; } from '../models';
import { createBot } from '../helpers/bot'; import { createBot } from '../helpers/bot';
import { EELicenseService } from '../ee/services';
import { SecretService } from '../services'; import { SecretService } from '../services';
/** /**
@@ -22,24 +23,25 @@ export const createWorkspace = async ({
name: string; name: string;
organizationId: string; organizationId: string;
}) => { }) => {
// create workspace // create workspace
const workspace = await new Workspace({ const workspace = await new Workspace({
name, name,
organization: organizationId, organization: organizationId,
autoCapitalization: true autoCapitalization: true
}).save(); }).save();
// initialize bot for workspace // initialize bot for workspace
await createBot({ await createBot({
name: 'Infisical Bot', name: 'Infisical Bot',
workspaceId: workspace._id workspaceId: workspace._id
}); });
// initialize blind index salt for workspace // initialize blind index salt for workspace
await SecretService.createSecretBlindIndexData({ await SecretService.createSecretBlindIndexData({
workspaceId: workspace._id workspaceId: workspace._id
}); });
await EELicenseService.refreshOrganizationPlan(organizationId);
return workspace; return workspace;
}; };

View File

@@ -1,7 +1,7 @@
export type SubscriptionPlan = { export type SubscriptionPlan = {
_id: string; _id: string;
membersUsed: number; membersUsed: number;
membersLimit: number; memberLimit: number;
auditLogs: boolean; auditLogs: boolean;
customAlerts: boolean; customAlerts: boolean;
customRateLimits: boolean; customRateLimits: boolean;

View File

@@ -61,7 +61,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
const { subscription } = useSubscription(); const { subscription } = useSubscription();
const host = window.location.origin; const host = window.location.origin;
const isAddingProjectsAllowed = ((subscription?.workspacesUsed || 1) < (subscription?.workspaceLimit || 3)) || host !== 'https://app.infisical.com'; const isAddingProjectsAllowed = subscription?.workspaceLimit ? (subscription.workspacesUsed < subscription.workspaceLimit) : true;
const createWs = useCreateWorkspace(); const createWs = useCreateWorkspace();
const uploadWsKey = useUploadWsKey(); const uploadWsKey = useUploadWsKey();

View File

@@ -60,7 +60,7 @@ export const OrgSettingsPage = () => {
const [completeInviteLink, setcompleteInviteLink] = useState<string | undefined>(''); const [completeInviteLink, setcompleteInviteLink] = useState<string | undefined>('');
const isMoreUsersNotAllowed = ((subscription?.membersUsed || 0) >= (subscription?.membersLimit || 1)) && host === 'https://app.infisical.com'; const isMoreUsersNotAllowed = subscription?.memberLimit ? (subscription.membersUsed >= subscription.memberLimit) : false;
const onRenameOrg = async (name: string) => { const onRenameOrg = async (name: string) => {
if (!currentOrg?._id) return; if (!currentOrg?._id) return;