improvements: address feedback

This commit is contained in:
Scott Wilson
2025-08-13 16:03:48 -07:00
parent b8fa4d5255
commit 90b93fbd15
8 changed files with 152 additions and 13 deletions
@@ -27,7 +27,23 @@ export const registerAccessApprovalRequestRouter = async (server: FastifyZodProv
body: z.object({
permissions: z.any().array(),
isTemporary: z.boolean(),
temporaryRange: z.string().optional(),
temporaryRange: z
.string()
.optional()
.transform((val, ctx) => {
if (!val || val === "permanent") return undefined;
const parsedMs = ms(val);
if (typeof parsedMs !== "number" || parsedMs <= 0) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "Invalid time period format or value. Must be a positive duration (e.g., '1h', '30m', '2d')."
});
return z.NEVER;
}
return val;
}),
note: z.string().max(255).optional()
}),
querystring: z.object({
@@ -346,7 +346,9 @@ export const accessApprovalRequestServiceFactory = ({
const project = await projectDAL.findById(accessApprovalRequest.projectId);
if (!project) {
throw new NotFoundError({ message: "The project associated with this access request was not found." });
throw new NotFoundError({
message: `The project associated with this access request was not found. [projectId=${accessApprovalRequest.projectId}]`
});
}
if (accessApprovalRequest.status !== ApprovalStatus.PENDING) {
@@ -355,7 +357,7 @@ export const accessApprovalRequestServiceFactory = ({
const editedByUser = await userDAL.findById(actorId);
if (!editedByUser) throw new ForbiddenRequestError({ message: "User not found" });
if (!editedByUser) throw new NotFoundError({ message: "Editing user not found" });
if (accessApprovalRequest.isTemporary && accessApprovalRequest.temporaryRange) {
if (ms(temporaryRange) > ms(accessApprovalRequest.temporaryRange)) {
@@ -394,7 +396,7 @@ export const accessApprovalRequestServiceFactory = ({
await triggerWorkflowIntegrationNotification({
input: {
notification: {
type: TriggerFeature.ACCESS_REQUEST,
type: TriggerFeature.ACCESS_REQUEST_UPDATED,
payload: {
projectName: project.name,
requesterFullName,
@@ -421,7 +423,9 @@ export const accessApprovalRequestServiceFactory = ({
});
await smtpService.sendMail({
recipients: policy.approvers.filter((approver) => approver.email).map((approver) => approver.email!),
recipients: policy.approvers
.filter((approver) => Boolean(approver.email) && approver.userId !== editedByUser.id)
.map((approver) => approver.email!),
subjectLine: "Access Approval Request Updated",
substitutions: {
projectName: project.name,