Skip to content

Commit 373156d

Browse files
authored
[codex] add audit log filters and CSV export (#33)
* feat: add audit log filters and export * fix: align audit log filter window * fix: address audit filter review comments * fix: sanitize csv headers
1 parent 1919fbd commit 373156d

4 files changed

Lines changed: 369 additions & 77 deletions

File tree

server/services/query-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ export const queryServiceHandlers: ServiceImpl<typeof QueryService> = {
12231223
requirePermission(user, req.connectionId, 'admin', 'view audit log');
12241224
getConnectionDetails(req.connectionId);
12251225

1226-
const limit = req.limit > 0 ? Math.min(req.limit, 500) : 100;
1226+
const limit = req.limit > 0 ? Math.min(req.limit, 1000) : 100;
12271227
const entries = listAuditEvents(req.connectionId, limit).map(toAuditLogEntry);
12281228

12291229
return { entries };
@@ -1241,7 +1241,7 @@ export const queryServiceHandlers: ServiceImpl<typeof QueryService> = {
12411241
throw new ConnectError("Permission denied: viewing the system audit log requires instance owner", Code.PermissionDenied);
12421242
}
12431243

1244-
const limit = req.limit > 0 ? Math.min(req.limit, 500) : 100;
1244+
const limit = req.limit > 0 ? Math.min(req.limit, 1000) : 100;
12451245
const entries = listSystemAuditEvents(limit).map(toAuditLogEntry);
12461246

12471247
return { entries };

src/hooks/useQuery.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,13 @@ export function useTerminateProcess() {
328328
});
329329
}
330330

331+
const AUDIT_LOG_LIMIT = 1000;
332+
331333
export function useAuditLogEntries(connectionId: string, enabled = true) {
332334
return useQuery({
333335
queryKey: queryKeys.auditLog(connectionId),
334336
queryFn: async () => {
335-
const response = await queryClient.getAuditLogEntries({ connectionId, limit: 100 });
337+
const response = await queryClient.getAuditLogEntries({ connectionId, limit: AUDIT_LOG_LIMIT });
336338
return response.entries;
337339
},
338340
enabled: enabled && !!connectionId,
@@ -346,7 +348,7 @@ export function useSystemAuditLogEntries(enabled = true) {
346348
return useQuery({
347349
queryKey: queryKeys.systemAuditLog(),
348350
queryFn: async () => {
349-
const response = await queryClient.getSystemAuditLogEntries({ limit: 100 });
351+
const response = await queryClient.getSystemAuditLogEntries({ limit: AUDIT_LOG_LIMIT });
350352
return response.entries;
351353
},
352354
enabled,

src/lib/export-csv.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import Papa from 'papaparse'
22
import type { ColumnMetadata } from '@/components/sql-editor/hooks/useEditorTabs'
33

4+
function sanitizeCsvString(value: string): string {
5+
return /^[\s]*[=+\-@\t\r]/.test(value) ? `'${value}` : value
6+
}
7+
8+
function sanitizeCsvCell(value: unknown): unknown {
9+
return typeof value === 'string' ? sanitizeCsvString(value) : value
10+
}
11+
412
export function exportToCsv(
5-
columns: ColumnMetadata[],
13+
columns: Array<Pick<ColumnMetadata, 'name'>>,
614
rows: Record<string, unknown>[],
715
filename: string
816
) {
917
const columnNames = columns.map((col) => col.name)
1018
const csv = Papa.unparse({
11-
fields: columnNames,
12-
data: rows.map((row) => columnNames.map((name) => row[name])),
19+
fields: columnNames.map((name) => sanitizeCsvString(name)),
20+
data: rows.map((row) => columnNames.map((name) => sanitizeCsvCell(row[name]))),
1321
})
1422

1523
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })

0 commit comments

Comments
 (0)