Update secret-approval-policy-service.ts

This commit is contained in:
Daniel Hougaard
2025-07-11 00:59:28 +04:00
parent 5e24015f2a
commit 97c96acea5
@@ -61,14 +61,13 @@ export const secretApprovalPolicyServiceFactory = ({
policyId policyId
}: { }: {
envId: string; envId: string;
secretPath?: string | null; secretPath: string;
policyId?: string; policyId?: string;
}) => { }) => {
const policy = await secretApprovalPolicyDAL const policy = await secretApprovalPolicyDAL
.findOne({ .findOne({
envId, envId,
// For environment-wide policies, we store the path as an empty string, even though the column is nullable; for that reason we check for an empty string. secretPath,
...(secretPath ? { secretPath } : { secretPath: "" }),
deletedAt: null deletedAt: null
}) })
.catch(() => null); .catch(() => null);
@@ -288,7 +287,13 @@ export const secretApprovalPolicyServiceFactory = ({
}); });
} }
if (await $policyExists({ envId: secretApprovalPolicy.envId, secretPath, policyId: secretApprovalPolicy.id })) { if (
await $policyExists({
envId: secretApprovalPolicy.envId,
secretPath: secretPath || secretApprovalPolicy.secretPath,
policyId: secretApprovalPolicy.id
})
) {
throw new BadRequestError({ throw new BadRequestError({
message: `A policy for secret path '${secretPath}' already exists in environment '${secretApprovalPolicy.environment.slug}'` message: `A policy for secret path '${secretPath}' already exists in environment '${secretApprovalPolicy.environment.slug}'`
}); });