From d5da5161c8cbeb125836203e70184bc1ea637679 Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Wed, 10 Sep 2025 14:48:33 -0700 Subject: [PATCH] improvement: address feedback --- backend/src/ee/routes/v2/index.ts | 2 +- .../dynamic-secret/providers/sql-database.ts | 2 +- .../ldap-config/ldap-config-service.ts | 10 ++-------- backend/src/ee/services/license/license-fns.ts | 18 ++++++++++++++++++ .../ee/services/oidc/oidc-config-service.ts | 10 ++-------- .../saml-config/saml-config-service.ts | 10 ++-------- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/backend/src/ee/routes/v2/index.ts b/backend/src/ee/routes/v2/index.ts index b7ee038a1..e082773dd 100644 --- a/backend/src/ee/routes/v2/index.ts +++ b/backend/src/ee/routes/v2/index.ts @@ -7,9 +7,9 @@ import { SECRET_SCANNING_REGISTER_ROUTER_MAP } from "@app/ee/routes/v2/secret-scanning-v2-routers"; +import { registerGatewayV2Router } from "./gateway-router"; import { registerIdentityProjectAdditionalPrivilegeRouter } from "./identity-project-additional-privilege-router"; import { registerProjectRoleRouter } from "./project-role-router"; -import { registerGatewayV2Router } from "./gateway-router"; export const registerV2EERoutes = async (server: FastifyZodProvider) => { // org role starts with organization diff --git a/backend/src/ee/services/dynamic-secret/providers/sql-database.ts b/backend/src/ee/services/dynamic-secret/providers/sql-database.ts index d831c7e7e..a9011b993 100644 --- a/backend/src/ee/services/dynamic-secret/providers/sql-database.ts +++ b/backend/src/ee/services/dynamic-secret/providers/sql-database.ts @@ -1,6 +1,6 @@ import handlebars from "handlebars"; -import RE2 from "re2"; import knex from "knex"; +import RE2 from "re2"; import { z } from "zod"; import { crypto } from "@app/lib/crypto/cryptography"; 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 3b1827480..8643ecdac 100644 --- a/backend/src/ee/services/ldap-config/ldap-config-service.ts +++ b/backend/src/ee/services/ldap-config/ldap-config-service.ts @@ -5,6 +5,7 @@ import { OrgMembershipStatus, TableName, TLdapConfigsUpdate, TUsers } from "@app import { TGroupDALFactory } from "@app/ee/services/group/group-dal"; import { addUsersToGroupByUserIds, removeUsersFromGroupByUserIds } from "@app/ee/services/group/group-fns"; import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal"; +import { throwOnPlanSeatLimitReached } from "@app/ee/services/license/license-fns"; import { getConfig } from "@app/lib/config/env"; import { crypto } from "@app/lib/crypto"; import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors"; @@ -465,14 +466,7 @@ export const ldapConfigServiceFactory = ({ ); if (!orgMembership) { - const plan = await licenseService.getPlan(orgId); - 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({ - message: - "Failed to create new member via LDAP due to member limit reached. Upgrade plan to add more members." - }); - } + await throwOnPlanSeatLimitReached(licenseService, orgId, UserAliasType.LDAP); const { role, roleId } = await getDefaultOrgMembershipRole(organization.defaultMembershipRole); diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.ts index 8d2d6fdbe..a302e956a 100644 --- a/backend/src/ee/services/license/license-fns.ts +++ b/backend/src/ee/services/license/license-fns.ts @@ -1,8 +1,11 @@ import axios, { AxiosError } from "axios"; +import { TLicenseServiceFactory } from "@app/ee/services/license/license-service"; import { getConfig } from "@app/lib/config/env"; import { request } from "@app/lib/config/request"; +import { BadRequestError } from "@app/lib/errors"; import { logger } from "@app/lib/logger"; +import { UserAliasType } from "@app/services/user-alias/user-alias-types"; import { TFeatureSet } from "./license-types"; @@ -133,3 +136,18 @@ export const setupLicenseRequestWithStore = ( return { request: licenseReq, refreshLicense }; }; + +export const throwOnPlanSeatLimitReached = async ( + licenseService: Pick, + orgId: string, + type?: UserAliasType +) => { + const plan = await licenseService.getPlan(orgId); + + 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({ + message: `Failed to create new member${type ? ` via ${type.toUpperCase()}` : ""} due to member limit reached. Upgrade plan to add more members.` + }); + } +}; diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.ts index 11d9f2724..445ace2b5 100644 --- a/backend/src/ee/services/oidc/oidc-config-service.ts +++ b/backend/src/ee/services/oidc/oidc-config-service.ts @@ -8,6 +8,7 @@ import { EventType, TAuditLogServiceFactory } from "@app/ee/services/audit-log/a import { TGroupDALFactory } from "@app/ee/services/group/group-dal"; import { addUsersToGroupByUserIds, removeUsersFromGroupByUserIds } from "@app/ee/services/group/group-fns"; import { TUserGroupMembershipDALFactory } from "@app/ee/services/group/user-group-membership-dal"; +import { throwOnPlanSeatLimitReached } from "@app/ee/services/license/license-fns"; 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-types"; @@ -294,14 +295,7 @@ export const oidcConfigServiceFactory = ({ ); if (!orgMembership) { - const plan = await licenseService.getPlan(orgId); - 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({ - message: - "Failed to create new member via OIDC due to member limit reached. Upgrade plan to add more members." - }); - } + await throwOnPlanSeatLimitReached(licenseService, orgId, UserAliasType.OIDC); const { role, roleId } = await getDefaultOrgMembershipRole(organization.defaultMembershipRole); 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 5a307f4f2..31aaa70aa 100644 --- a/backend/src/ee/services/saml-config/saml-config-service.ts +++ b/backend/src/ee/services/saml-config/saml-config-service.ts @@ -1,6 +1,7 @@ import { ForbiddenError } from "@casl/ability"; import { OrgMembershipStatus, TableName, TSamlConfigs, TSamlConfigsUpdate, TUsers } from "@app/db/schemas"; +import { throwOnPlanSeatLimitReached } from "@app/ee/services/license/license-fns"; import { getConfig } from "@app/lib/config/env"; import { crypto } from "@app/lib/crypto"; import { BadRequestError, ForbiddenRequestError, NotFoundError } from "@app/lib/errors"; @@ -383,14 +384,7 @@ export const samlConfigServiceFactory = ({ ); if (!orgMembership) { - const plan = await licenseService.getPlan(orgId); - 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({ - message: - "Failed to create new member via SAML due to member limit reached. Upgrade plan to add more members." - }); - } + await throwOnPlanSeatLimitReached(licenseService, orgId, UserAliasType.SAML); const { role, roleId } = await getDefaultOrgMembershipRole(organization.defaultMembershipRole);