mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-22 20:20:29 +02:00
✨ Implement IP filtering for admin access logs
This commit is contained in:
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user