Greptile review fixes

This commit is contained in:
x032205
2025-05-27 21:11:19 -04:00
parent 8f010e740f
commit accb21f7ed
3 changed files with 12 additions and 3 deletions
@@ -27,6 +27,7 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.max(100, "Cannot have more than 100 approvers")
.min(1, { message: "At least one approver should be provided" }), .min(1, { message: "At least one approver should be provided" }),
bypassers: z bypassers: z
.discriminatedUnion("type", [ .discriminatedUnion("type", [
@@ -34,6 +35,7 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.max(100, "Cannot have more than 100 bypassers")
.optional(), .optional(),
approvals: z.number().min(1).default(1), approvals: z.number().min(1).default(1),
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard), enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
@@ -154,13 +156,15 @@ export const registerAccessApprovalPolicyRouter = async (server: FastifyZodProvi
z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.min(1, { message: "At least one approver should be provided" }), .min(1, { message: "At least one approver should be provided" })
.max(100, "Cannot have more than 100 approvers"),
bypassers: z bypassers: z
.discriminatedUnion("type", [ .discriminatedUnion("type", [
z.object({ type: z.literal(BypasserType.Group), id: z.string() }), z.object({ type: z.literal(BypasserType.Group), id: z.string() }),
z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.max(100, "Cannot have more than 100 bypassers")
.optional(), .optional(),
approvals: z.number().min(1).optional(), approvals: z.number().min(1).optional(),
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard), enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
@@ -33,13 +33,15 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.min(1, { message: "At least one approver should be provided" }), .min(1, { message: "At least one approver should be provided" })
.max(100, "Cannot have more than 100 approvers"),
bypassers: z bypassers: z
.discriminatedUnion("type", [ .discriminatedUnion("type", [
z.object({ type: z.literal(BypasserType.Group), id: z.string() }), z.object({ type: z.literal(BypasserType.Group), id: z.string() }),
z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.max(100, "Cannot have more than 100 bypassers")
.optional(), .optional(),
approvals: z.number().min(1).default(1), approvals: z.number().min(1).default(1),
enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard), enforcementLevel: z.nativeEnum(EnforcementLevel).default(EnforcementLevel.Hard),
@@ -85,13 +87,15 @@ export const registerSecretApprovalPolicyRouter = async (server: FastifyZodProvi
z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(ApproverType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.min(1, { message: "At least one approver should be provided" }), .min(1, { message: "At least one approver should be provided" })
.max(100, "Cannot have more than 100 approvers"),
bypassers: z bypassers: z
.discriminatedUnion("type", [ .discriminatedUnion("type", [
z.object({ type: z.literal(BypasserType.Group), id: z.string() }), z.object({ type: z.literal(BypasserType.Group), id: z.string() }),
z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() }) z.object({ type: z.literal(BypasserType.User), id: z.string().optional(), name: z.string().optional() })
]) ])
.array() .array()
.max(100, "Cannot have more than 100 bypassers")
.optional(), .optional(),
approvals: z.number().min(1).default(1), approvals: z.number().min(1).default(1),
secretPath: z secretPath: z
@@ -359,6 +359,7 @@ export const accessApprovalRequestServiceFactory = ({
const isApprover = policy.approvers.find((approver) => approver.userId === actorId); const isApprover = policy.approvers.find((approver) => approver.userId === actorId);
// If user is (not an approver OR cant self approve) AND can't bypass policy
if ((!isApprover || (!policy.allowedSelfApprovals && isSelfApproval)) && cannotBypassUnderSoftEnforcement) { if ((!isApprover || (!policy.allowedSelfApprovals && isSelfApproval)) && cannotBypassUnderSoftEnforcement) {
throw new BadRequestError({ throw new BadRequestError({
message: "Failed to review access approval request. Users are not authorized to review their own request." message: "Failed to review access approval request. Users are not authorized to review their own request."