From e0c774c045c1bb2e4f5e3483a649501d7358f4bc Mon Sep 17 00:00:00 2001 From: Maidul Islam Date: Tue, 25 Jun 2024 18:03:07 -0400 Subject: [PATCH] Revert "Add support for Identity-Based Pricing" --- .infisicalignore | 1 - .../ldap-config/ldap-config-service.ts | 15 -------- .../services/license/__mocks__/licence-fns.ts | 2 - .../src/ee/services/license/licence-fns.ts | 2 - .../src/ee/services/license/license-dal.ts | 37 +------------------ .../ee/services/license/license-service.ts | 13 ++----- .../src/ee/services/license/license-types.ts | 2 - .../saml-config/saml-config-service.ts | 15 -------- backend/src/server/routes/index.ts | 3 +- .../src/services/identity/identity-service.ts | 17 +-------- backend/src/services/org/org-service.ts | 13 ++----- frontend/src/hooks/api/subscriptions/types.ts | 2 - .../IdentitySection/IdentitySection.tsx | 30 ++------------- .../OrgMembersSection/OrgMembersSection.tsx | 18 ++++----- 14 files changed, 21 insertions(+), 149 deletions(-) diff --git a/.infisicalignore b/.infisicalignore index b7fc38b356..855047fe4c 100644 --- a/.infisicalignore +++ b/.infisicalignore @@ -5,4 +5,3 @@ frontend/src/views/Project/MembersPage/components/MemberListTab/MemberRoleForm/M frontend/src/views/Project/MembersPage/components/MemberListTab/MemberRoleForm/SpecificPrivilegeSection.tsx:generic-api-key:292 docs/self-hosting/configuration/envars.mdx:generic-api-key:106 frontend/src/views/Project/MembersPage/components/MemberListTab/MemberRoleForm/SpecificPrivilegeSection.tsx:generic-api-key:451 -docs/mint.json:generic-api-key:651 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 b63ecda109..63565d94c2 100644 --- a/backend/src/ee/services/ldap-config/ldap-config-service.ts +++ b/backend/src/ee/services/ldap-config/ldap-config-service.ts @@ -450,21 +450,6 @@ export const ldapConfigServiceFactory = ({ } }); } else { - const plan = await licenseService.getPlan(orgId); - if (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?.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({ - message: "Failed to create new member via LDAP due to member limit reached. Upgrade plan to add more members." - }); - } - userAlias = await userDAL.transaction(async (tx) => { let newUser: TUsers | undefined; if (serverCfg.trustSamlEmails) { diff --git a/backend/src/ee/services/license/__mocks__/licence-fns.ts b/backend/src/ee/services/license/__mocks__/licence-fns.ts index a8b3b351dc..ddbffba457 100644 --- a/backend/src/ee/services/license/__mocks__/licence-fns.ts +++ b/backend/src/ee/services/license/__mocks__/licence-fns.ts @@ -7,8 +7,6 @@ export const getDefaultOnPremFeatures = () => { workspacesUsed: 0, memberLimit: null, membersUsed: 0, - identityLimit: null, - identitiesUsed: 0, environmentLimit: null, environmentsUsed: 0, secretVersioning: true, diff --git a/backend/src/ee/services/license/licence-fns.ts b/backend/src/ee/services/license/licence-fns.ts index d69f7bf955..46cc656d5a 100644 --- a/backend/src/ee/services/license/licence-fns.ts +++ b/backend/src/ee/services/license/licence-fns.ts @@ -15,8 +15,6 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({ membersUsed: 0, environmentLimit: null, environmentsUsed: 0, - identityLimit: null, - identitiesUsed: 0, dynamicSecret: false, secretVersioning: true, pitRecovery: false, diff --git a/backend/src/ee/services/license/license-dal.ts b/backend/src/ee/services/license/license-dal.ts index 5cbfca1d6f..cf70488019 100644 --- a/backend/src/ee/services/license/license-dal.ts +++ b/backend/src/ee/services/license/license-dal.ts @@ -19,44 +19,11 @@ export const licenseDALFactory = (db: TDbClient) => { .join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`) .where(`${TableName.Users}.isGhost`, false) .count(); - return Number(doc?.[0].count); + return doc?.[0].count; } catch (error) { throw new DatabaseError({ error, name: "Count of Org Members" }); } }; - const countOrgUsersAndIdentities = async (orgId: string | null, tx?: Knex) => { - try { - // count org users - const userDoc = await (tx || db)(TableName.OrgMembership) - .where({ status: OrgMembershipStatus.Accepted }) - .andWhere((bd) => { - if (orgId) { - void bd.where({ orgId }); - } - }) - .join(TableName.Users, `${TableName.OrgMembership}.userId`, `${TableName.Users}.id`) - .where(`${TableName.Users}.isGhost`, false) - .count(); - - const userCount = Number(userDoc?.[0].count); - - // count org identities - const identityDoc = await (tx || db)(TableName.IdentityOrgMembership) - .where((bd) => { - if (orgId) { - void bd.where({ orgId }); - } - }) - .count(); - - const identityCount = Number(identityDoc?.[0].count); - - return userCount + identityCount; - } catch (error) { - throw new DatabaseError({ error, name: "Count of Org Users + Identities" }); - } - }; - - return { countOfOrgMembers, countOrgUsersAndIdentities }; + return { countOfOrgMembers }; }; diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.ts index 0b0fec53ab..46931468fd 100644 --- a/backend/src/ee/services/license/license-service.ts +++ b/backend/src/ee/services/license/license-service.ts @@ -155,7 +155,6 @@ export const licenseServiceFactory = ({ LICENSE_SERVER_CLOUD_PLAN_TTL, JSON.stringify(currentPlan) ); - return currentPlan; } } catch (error) { @@ -205,22 +204,16 @@ export const licenseServiceFactory = ({ const org = await orgDAL.findOrgById(orgId); if (!org) throw new BadRequestError({ message: "Org not found" }); - const quantity = await licenseDAL.countOfOrgMembers(orgId); - const quantityIdentities = await licenseDAL.countOrgUsersAndIdentities(orgId); + const count = await licenseDAL.countOfOrgMembers(orgId); if (org?.customerId) { await licenseServerCloudApi.request.patch(`/api/license-server/v1/customers/${org.customerId}/cloud-plan`, { - quantity, - quantityIdentities + quantity: count }); } await keyStore.deleteItem(FEATURE_CACHE_KEY(orgId)); } else if (instanceType === InstanceType.EnterpriseOnPrem) { const usedSeats = await licenseDAL.countOfOrgMembers(null); - const usedIdentitySeats = await licenseDAL.countOrgUsersAndIdentities(null); - await licenseServerOnPremApi.request.patch(`/api/license/v1/license`, { - usedSeats, - usedIdentitySeats - }); + await licenseServerOnPremApi.request.patch(`/api/license/v1/license`, { usedSeats }); } await refreshPlan(orgId); }; diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.ts index 36b03ff803..9e1bdd9b32 100644 --- a/backend/src/ee/services/license/license-types.ts +++ b/backend/src/ee/services/license/license-types.ts @@ -31,8 +31,6 @@ export type TFeatureSet = { dynamicSecret: false; memberLimit: null; membersUsed: 0; - identityLimit: null; - identitiesUsed: 0; environmentLimit: null; environmentsUsed: 0; secretVersioning: true; 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 08a13bf067..3cc51e1c20 100644 --- a/backend/src/ee/services/saml-config/saml-config-service.ts +++ b/backend/src/ee/services/saml-config/saml-config-service.ts @@ -380,21 +380,6 @@ export const samlConfigServiceFactory = ({ return foundUser; }); } else { - const plan = await licenseService.getPlan(orgId); - if (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?.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({ - message: "Failed to create new member via SAML due to member limit reached. Upgrade plan to add more members." - }); - } - user = await userDAL.transaction(async (tx) => { let newUser: TUsers | undefined; if (serverCfg.trustSamlEmails) { diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts index a748396d4b..dfcbf82cfa 100644 --- a/backend/src/server/routes/index.ts +++ b/backend/src/server/routes/index.ts @@ -806,8 +806,7 @@ export const registerRoutes = async ( const identityService = identityServiceFactory({ permissionService, identityDAL, - identityOrgMembershipDAL, - licenseService + identityOrgMembershipDAL }); const identityAccessTokenService = identityAccessTokenServiceFactory({ identityAccessTokenDAL, diff --git a/backend/src/services/identity/identity-service.ts b/backend/src/services/identity/identity-service.ts index f6eccfb99e..7d44cfdd4e 100644 --- a/backend/src/services/identity/identity-service.ts +++ b/backend/src/services/identity/identity-service.ts @@ -1,7 +1,6 @@ import { ForbiddenError } from "@casl/ability"; import { OrgMembershipRole, TableName, TOrgRoles } from "@app/db/schemas"; -import { TLicenseServiceFactory } from "@app/ee/services/license/license-service"; import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission"; import { TPermissionServiceFactory } from "@app/ee/services/permission/permission-service"; import { isAtLeastAsPrivileged } from "@app/lib/casl"; @@ -17,7 +16,6 @@ type TIdentityServiceFactoryDep = { identityDAL: TIdentityDALFactory; identityOrgMembershipDAL: TIdentityOrgDALFactory; permissionService: Pick; - licenseService: Pick; }; export type TIdentityServiceFactory = ReturnType; @@ -25,8 +23,7 @@ export type TIdentityServiceFactory = ReturnType; export const identityServiceFactory = ({ identityDAL, identityOrgMembershipDAL, - permissionService, - licenseService + permissionService }: TIdentityServiceFactoryDep) => { const createIdentity = async ({ name, @@ -48,14 +45,6 @@ export const identityServiceFactory = ({ const hasRequiredPriviledges = isAtLeastAsPrivileged(permission, rolePermission); if (!hasRequiredPriviledges) throw new BadRequestError({ message: "Failed to create a more privileged identity" }); - const plan = await licenseService.getPlan(orgId); - if (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({ - message: "Failed to create identity due to identity limit reached. Upgrade plan to create more identities." - }); - } - const identity = await identityDAL.transaction(async (tx) => { const newIdentity = await identityDAL.create({ name }, tx); await identityOrgMembershipDAL.create( @@ -69,7 +58,6 @@ export const identityServiceFactory = ({ ); return newIdentity; }); - await licenseService.updateSubscriptionOrgMemberCount(orgId); return identity; }; @@ -180,9 +168,6 @@ export const identityServiceFactory = ({ throw new ForbiddenRequestError({ message: "Failed to delete more privileged identity" }); const deletedIdentity = await identityDAL.deleteById(id); - - await licenseService.updateSubscriptionOrgMemberCount(identityOrgMembership.orgId); - return { ...deletedIdentity, orgId: identityOrgMembership.orgId }; }; diff --git a/backend/src/services/org/org-service.ts b/backend/src/services/org/org-service.ts index 248bab5680..68d2b8cda2 100644 --- a/backend/src/services/org/org-service.ts +++ b/backend/src/services/org/org-service.ts @@ -420,20 +420,13 @@ export const orgServiceFactory = ({ } const plan = await licenseService.getPlan(orgId); - if (plan?.memberLimit && plan.membersUsed >= plan.memberLimit) { - // limit imposed on number of members allowed / number of members used exceeds the number of members allowed + if (plan.memberLimit !== null && plan.membersUsed >= plan.memberLimit) { + // case: limit imposed on number of members allowed + // case: number of members used exceeds the number of members allowed throw new BadRequestError({ message: "Failed to invite member due to member limit reached. Upgrade plan to invite more members." }); } - - if (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({ - message: "Failed to invite member due to member limit reached. Upgrade plan to invite more members." - }); - } - const invitee = await orgDAL.transaction(async (tx) => { const inviteeUser = await userDAL.findUserByUsername(inviteeEmail, tx); if (inviteeUser) { diff --git a/frontend/src/hooks/api/subscriptions/types.ts b/frontend/src/hooks/api/subscriptions/types.ts index 89635a9533..6b94258000 100644 --- a/frontend/src/hooks/api/subscriptions/types.ts +++ b/frontend/src/hooks/api/subscriptions/types.ts @@ -2,8 +2,6 @@ export type SubscriptionPlan = { id: string; membersUsed: number; memberLimit: number; - identitiesUsed: number; - identityLimit: number; auditLogs: boolean; dynamicSecret: boolean; auditLogsRetentionDays: number; diff --git a/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx b/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx index b8b1f1708c..c5ebf7c55b 100644 --- a/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx +++ b/frontend/src/views/Org/MembersPage/components/OrgIdentityTab/components/IdentitySection/IdentitySection.tsx @@ -4,13 +4,8 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { createNotification } from "@app/components/notifications"; import { OrgPermissionCan } from "@app/components/permissions"; -import { Button, DeleteActionModal, UpgradePlanModal } from "@app/components/v2"; -import { - OrgPermissionActions, - OrgPermissionSubjects, - useOrganization, - useSubscription -} from "@app/context"; +import { Button, DeleteActionModal } from "@app/components/v2"; +import { OrgPermissionActions, OrgPermissionSubjects, useOrganization } from "@app/context"; import { withPermission } from "@app/hoc"; import { useDeleteIdentity } from "@app/hooks/api"; import { usePopUp } from "@app/hooks/usePopUp"; @@ -22,10 +17,10 @@ import { IdentityUniversalAuthClientSecretModal } from "./IdentityUniversalAuthC export const IdentitySection = withPermission( () => { - const { subscription } = useSubscription(); const { currentOrg } = useOrganization(); const orgId = currentOrg?.id || ""; + const { mutateAsync: deleteMutateAsync } = useDeleteIdentity(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "identity", @@ -36,10 +31,6 @@ export const IdentitySection = withPermission( "upgradePlan" ] as const); - const isMoreIdentitiesAllowed = subscription?.identityLimit - ? subscription.identitiesUsed < subscription.identityLimit - : true; - const onDeleteIdentitySubmit = async (identityId: string) => { try { await deleteMutateAsync({ @@ -90,15 +81,7 @@ export const IdentitySection = withPermission( colorSchema="primary" type="submit" leftIcon={} - onClick={() => { - if (!isMoreIdentitiesAllowed) { - handlePopUpOpen("upgradePlan", { - description: "You can add more identities if you upgrade your Infisical plan." - }); - return; - } - handlePopUpOpen("identity"); - }} + onClick={() => handlePopUpOpen("identity")} isDisabled={!isAllowed} > Create identity @@ -135,11 +118,6 @@ export const IdentitySection = withPermission( ) } /> - handlePopUpToggle("upgradePlan", isOpen)} - text={(popUp.upgradePlan?.data as { description: string })?.description} - /> ); }, diff --git a/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx b/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx index 8943f29402..17f32369c5 100644 --- a/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx +++ b/frontend/src/views/Org/MembersPage/components/OrgMembersTab/components/OrgMembersSection/OrgMembersSection.tsx @@ -23,6 +23,7 @@ import { AddOrgMemberModal } from "./AddOrgMemberModal"; import { OrgMembersTable } from "./OrgMembersTable"; export const OrgMembersSection = () => { + const { subscription } = useSubscription(); const { currentOrg } = useOrganization(); const orgId = currentOrg?.id ?? ""; @@ -38,13 +39,9 @@ export const OrgMembersSection = () => { const { mutateAsync: deleteMutateAsync } = useDeleteOrgMembership(); - const isMoreUsersAllowed = subscription?.memberLimit - ? subscription.membersUsed < subscription.memberLimit - : true; - - const isMoreIdentitiesAllowed = subscription?.identityLimit - ? subscription.identitiesUsed < subscription.identityLimit - : true; + const isMoreUsersNotAllowed = subscription?.memberLimit + ? subscription.membersUsed >= subscription.memberLimit + : false; const handleAddMemberModal = () => { if (currentOrg?.authEnforced) { @@ -55,14 +52,13 @@ export const OrgMembersSection = () => { return; } - if (!isMoreUsersAllowed || !isMoreIdentitiesAllowed) { + if (isMoreUsersNotAllowed) { handlePopUpOpen("upgradePlan", { description: "You can add more members if you upgrade your Infisical plan." }); - return; + } else { + handlePopUpOpen("addMember"); } - - handlePopUpOpen("addMember"); }; const onRemoveMemberSubmit = async (orgMembershipId: string) => {