Implement IP filtering for admin access logs

This commit is contained in:
Fred KISSIE
2026-08-21 22:49:45 +02:00
parent 2c197fab9f
commit 6a5ecab013
4 changed files with 79 additions and 18 deletions
@@ -88,7 +88,27 @@ export const queryAccessAuditLogsQuery = z.object({
.optional()
.default("0")
.transform(Number)
.pipe(z.int().nonnegative())
.pipe(z.int().nonnegative()),
ip: z
.preprocess((val) => {
if (val === undefined || val === null || val === "") {
return undefined;
}
if (Array.isArray(val)) {
return val;
}
// the array is returned as this
if (typeof val === "string") {
return val.split(",");
}
return undefined;
}, z.array(z.string()))
.optional()
.catch([])
.openapi({
type: "array",
description: "Filter by IP adresses"
})
});
export const queryAccessAuditLogsParams = z.object({
@@ -134,7 +154,8 @@ function getWhere(data: Q) {
data.type ? eq(accessAuditLog.type, data.type) : undefined,
data.action !== undefined
? eq(accessAuditLog.action, data.action)
: undefined
: undefined,
data.ip ? inArray(accessAuditLog.ip, data.ip) : undefined
);
}