From db369b8f513aa79add4678e7ceeafcf619a8910a Mon Sep 17 00:00:00 2001 From: Carlos Monastyrski Date: Fri, 11 Jul 2025 11:36:25 -0300 Subject: [PATCH] fix(billing): fix feature flags to only use identityLimit and minor fix invalidate plan query result --- .../src/ee/services/ldap-config/ldap-config-service.ts | 7 ------- backend/src/ee/services/license/licence-enums.ts | 1 - backend/src/ee/services/license/license-service.ts | 10 +++------- .../src/ee/services/saml-config/saml-config-service.ts | 7 ------- backend/src/services/org/org-service.ts | 8 -------- frontend/src/hooks/api/identities/mutations.tsx | 7 +++++++ frontend/src/hooks/api/users/queries.tsx | 4 ++++ .../components/OrgMembersSection/OrgMembersSection.tsx | 6 +----- 8 files changed, 15 insertions(+), 35 deletions(-) diff --git a/backend/src/ee/services/ldap-config/ldap-config-service.ts b/backend/src/ee/services/ldap-config/ldap-config-service.ts index 426ed132e..f85d88cd3 100644 --- a/backend/src/ee/services/ldap-config/ldap-config-service.ts +++ b/backend/src/ee/services/ldap-config/ldap-config-service.ts @@ -361,13 +361,6 @@ export const ldapConfigServiceFactory = ({ }); } else { const plan = await licenseService.getPlan(orgId); - if (plan?.slug !== "enterprise" && plan?.memberLimit && plan.membersUsed >= plan.memberLimit) { - // limit imposed on number of members allowed / number of members used exceeds the number of members allowed - throw new BadRequestError({ - message: "Failed to create new member via LDAP due to member limit reached. Upgrade plan to add more members." - }); - } - if (plan?.slug !== "enterprise" && plan?.identityLimit && plan.identitiesUsed >= plan.identityLimit) { // limit imposed on number of identities allowed / number of identities used exceeds the number of identities allowed throw new BadRequestError({ diff --git a/backend/src/ee/services/license/licence-enums.ts b/backend/src/ee/services/license/licence-enums.ts index 8812621f2..340fc764f 100644 --- a/backend/src/ee/services/license/licence-enums.ts +++ b/backend/src/ee/services/license/licence-enums.ts @@ -1,5 +1,4 @@ export const BillingPlanRows = { - MemberLimit: { name: "Organization member limit", field: "memberLimit" }, IdentityLimit: { name: "Organization identity limit", field: "identityLimit" }, WorkspaceLimit: { name: "Project limit", field: "workspaceLimit" }, EnvironmentLimit: { name: "Environment limit", field: "environmentLimit" }, diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.ts index b841c5bea..7e784d9ad 100644 --- a/backend/src/ee/services/license/license-service.ts +++ b/backend/src/ee/services/license/license-service.ts @@ -442,9 +442,7 @@ export const licenseServiceFactory = ({ rows: data.rows.map((el) => { let used = "-"; - if (el.name === BillingPlanRows.MemberLimit.name) { - used = orgMembersUsed.toString(); - } else if (el.name === BillingPlanRows.WorkspaceLimit.name) { + if (el.name === BillingPlanRows.WorkspaceLimit.name) { used = projectCount.toString(); } else if (el.name === BillingPlanRows.IdentityLimit.name) { used = (identityUsed + orgMembersUsed).toString(); @@ -464,12 +462,10 @@ export const licenseServiceFactory = ({ const allowed = onPremFeatures[field as keyof TFeatureSet]; let used = "-"; - if (field === BillingPlanRows.MemberLimit.field) { - used = orgMembersUsed.toString(); - } else if (field === BillingPlanRows.WorkspaceLimit.field) { + if (field === BillingPlanRows.WorkspaceLimit.field) { used = projectCount.toString(); } else if (field === BillingPlanRows.IdentityLimit.field) { - used = identityUsed.toString(); + used = (identityUsed + orgMembersUsed).toString(); } return { diff --git a/backend/src/ee/services/saml-config/saml-config-service.ts b/backend/src/ee/services/saml-config/saml-config-service.ts index 5430b0afc..4ab5c29e3 100644 --- a/backend/src/ee/services/saml-config/saml-config-service.ts +++ b/backend/src/ee/services/saml-config/saml-config-service.ts @@ -311,13 +311,6 @@ export const samlConfigServiceFactory = ({ }); } else { const plan = await licenseService.getPlan(orgId); - if (plan?.slug !== "enterprise" && plan?.memberLimit && plan.membersUsed >= plan.memberLimit) { - // limit imposed on number of members allowed / number of members used exceeds the number of members allowed - throw new BadRequestError({ - message: "Failed to create new member via SAML due to member limit reached. Upgrade plan to add more members." - }); - } - if (plan?.slug !== "enterprise" && plan?.identityLimit && plan.identitiesUsed >= plan.identityLimit) { // limit imposed on number of identities allowed / number of identities used exceeds the number of identities allowed throw new BadRequestError({ diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts index 8917a4fc1..de518c829 100644 --- a/backend/src/services/org/org-service.ts +++ b/backend/src/services/org/org-service.ts @@ -912,14 +912,6 @@ export const orgServiceFactory = ({ // if there exist no org membership we set is as given by the request if (!inviteeOrgMembership) { - if (plan?.slug !== "enterprise" && plan?.memberLimit && plan.membersUsed >= plan.memberLimit) { - // limit imposed on number of members allowed / number of members used exceeds the number of members allowed - throw new BadRequestError({ - name: "InviteUser", - message: "Failed to invite member due to member limit reached. Upgrade plan to invite more members." - }); - } - if (plan?.slug !== "enterprise" && plan?.identityLimit && plan.identitiesUsed >= plan.identityLimit) { // limit imposed on number of identities allowed / number of identities used exceeds the number of identities allowed throw new BadRequestError({ diff --git a/frontend/src/hooks/api/identities/mutations.tsx b/frontend/src/hooks/api/identities/mutations.tsx index dfbf574e8..55aaee6ef 100644 --- a/frontend/src/hooks/api/identities/mutations.tsx +++ b/frontend/src/hooks/api/identities/mutations.tsx @@ -3,6 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; import { apiRequest } from "@app/config/request"; import { organizationKeys } from "../organization/queries"; +import { subscriptionQueryKeys } from "../subscriptions/queries"; import { identitiesKeys } from "./queries"; import { AddIdentityAliCloudAuthDTO, @@ -82,6 +83,9 @@ export const useCreateIdentity = () => { queryClient.invalidateQueries({ queryKey: organizationKeys.getOrgIdentityMemberships(organizationId) }); + queryClient.invalidateQueries({ + queryKey: subscriptionQueryKeys.getOrgSubsription(organizationId) + }); } }); }; @@ -123,6 +127,9 @@ export const useDeleteIdentity = () => { queryClient.invalidateQueries({ queryKey: organizationKeys.getOrgIdentityMemberships(organizationId) }); + queryClient.invalidateQueries({ + queryKey: subscriptionQueryKeys.getOrgSubsription(organizationId) + }); } }); }; diff --git a/frontend/src/hooks/api/users/queries.tsx b/frontend/src/hooks/api/users/queries.tsx index ea451db02..b740b58ee 100644 --- a/frontend/src/hooks/api/users/queries.tsx +++ b/frontend/src/hooks/api/users/queries.tsx @@ -9,6 +9,7 @@ import { APIKeyDataV2 } from "../apiKeys/types"; import { MfaMethod } from "../auth/types"; import { TGroupWithProjectMemberships } from "../groups/types"; import { setAuthToken } from "../reactQuery"; +import { subscriptionQueryKeys } from "../subscriptions/queries"; import { workspaceKeys } from "../workspace"; import { userKeys } from "./query-keys"; import { @@ -188,6 +189,9 @@ export const useAddUsersToOrg = () => { }, onSuccess: (_, { organizationId, projects }) => { queryClient.invalidateQueries({ queryKey: userKeys.getOrgUsers(organizationId) }); + queryClient.invalidateQueries({ + queryKey: subscriptionQueryKeys.getOrgSubsription(organizationId) + }); projects?.forEach((project) => { if (project.slug) { diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx index 87e55c145..19f05f763 100644 --- a/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx +++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx @@ -39,10 +39,6 @@ export const OrgMembersSection = () => { const { mutateAsync: deleteMutateAsync } = useDeleteOrgMembership(); const { mutateAsync: updateOrgMembership } = useUpdateOrgMembership(); - const isMoreUsersAllowed = subscription?.memberLimit - ? subscription.membersUsed < subscription.memberLimit - : true; - const isMoreIdentitiesAllowed = subscription?.identityLimit ? subscription.identitiesUsed < subscription.identityLimit : true; @@ -58,7 +54,7 @@ export const OrgMembersSection = () => { return; } - if ((!isMoreUsersAllowed || !isMoreIdentitiesAllowed) && !isEnterprise) { + if (!isMoreIdentitiesAllowed && !isEnterprise) { handlePopUpOpen("upgradePlan", { description: "You can add more members if you upgrade your Infisical plan." });