Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
fix: address PR review comment
IgorHortaf50096353cd9
diff --git a/backend/src/ee/services/group/group-dal.ts b/backend/src/ee/services/group/group-dal.tsindex 2f24af5388..6a235e60a1 100644--- a/backend/src/ee/services/group/group-dal.ts+++ b/backend/src/ee/services/group/group-dal.ts@@ -595,18 +595,17 @@ export const groupDALFactory = (db: TDbClient) => {};/**- * Returns true if any group references the given group via sourceGroupId (self-referential FK).- * Used to block delete when this group is the source of linked/copied groups.+ * Returns the groups that reference the given group via sourceGroupId (self-referential FK).+ * Used to block delete when this group is the source of linked/copied groups; error message can list them.*/- const hasGroupsReferencingGroup = async (groupId: string, tx?: Knex): Promise<boolean> => {+ const getGroupsReferencingGroup = async (groupId: string, tx?: Knex): Promise<{ id: string; name: string }[]> => {try {- const row = await (tx || db.replicaNode())(TableName.Groups)+ const docs = await (tx || db.replicaNode())(TableName.Groups).whereRaw('"sourceGroupId" = ?', [groupId])- .select("id")- .first();- return Boolean(row);+ .select("id", "name");+ return docs;} catch (error) {- throw new DatabaseError({ error, name: "Has groups referencing group" });+ throw new DatabaseError({ error, name: "Get groups referencing group" });}};@@ -622,6 +621,6 @@ export const groupDALFactory = (db: TDbClient) => {findGroupsByProjectId,findById,findOne,- hasGroupsReferencingGroup+ getGroupsReferencingGroup};};diff --git a/backend/src/ee/services/group/group-service.ts b/backend/src/ee/services/group/group-service.tsindex 5f10b8338d..a3f746b6ab 100644--- a/backend/src/ee/services/group/group-service.ts+++ b/backend/src/ee/services/group/group-service.ts@@ -61,7 +61,7 @@ type TGroupServiceFactoryDep = {| "transaction"| "findAllGroupProjects"| "listAvailableGroups"- | "hasGroupsReferencingGroup"+ | "getGroupsReferencingGroup">;membershipGroupDAL: Pick<TMembershipGroupDALFactory, "find" | "findOne" | "create" | "getGroupById" | "deleteById">;membershipDAL: Pick<TMembershipDALFactory, "find" | "findOne">;@@ -339,11 +339,11 @@ export const groupServiceFactory = ({return group;}- const isReferencedAsSource = await groupDAL.hasGroupsReferencingGroup(id);- if (isReferencedAsSource) {+ const referencingGroups = await groupDAL.getGroupsReferencingGroup(id);+ if (referencingGroups.length > 0) {+ const groupList = referencingGroups.map((g) => `"${g.name}"`).join(", ");throw new BadRequestError({- message:- "Cannot delete this group because it is used as a source group by other groups. Unlink or delete those groups first."+ message: `Cannot delete this group because it is used as a source by other groups. Unlink or delete these groups first: ${groupList}.`});}