feat(audit): tenant-scoped CSV export endpoint (PMS-455) #333

Merged
YousifShkara merged 1 commit from feat/PMS-455-audit-log-csv-export into main 2026-06-23 07:32:03 +02:00
Owner

GET /api/v1/audit-log/export.csv streams the same admin-gated, tenant-scoped audit-log feed GET /audit-log already exposes, but as a CSV download instead of a paginated JSON page. Same AuditLogFilter envelope (date range / action / entity-type / actor) so an operator can scope the export to whatever they were reviewing in the SPA. Hard cap of 50k rows per request keeps a runaway filter from holding a connection; the SPA narrows by date range when the cap clips.

Response carries Content-Type: text/csv; charset=utf-8 and Content-Disposition: attachment; filename="audit-log.csv" so the browser triggers a download. Column order matches what an operator typically pivots on in a spreadsheet review: when -> who -> what -> target -> network metadata (timestamp / actor / actor_id / action / entity_type / entity_id / entity_name / ip_address / user_agent). RFC-4180 quoting on any field containing a comma, quote, or newline. System-issued rows render the actor as System to match the SPA's table convention.

This closes the audit / export half of PMS-455. The existing /audit-log JSON list + the AuditCtx helper writes from every privileged-action handler were already in place; this PR adds the export verb the original ticket called for. The client-side "Download CSV" button on /admin/audit-log lands in a sibling PR on mokosh-apps.

#PMS-455

`GET /api/v1/audit-log/export.csv` streams the same admin-gated, tenant-scoped audit-log feed `GET /audit-log` already exposes, but as a CSV download instead of a paginated JSON page. Same `AuditLogFilter` envelope (date range / action / entity-type / actor) so an operator can scope the export to whatever they were reviewing in the SPA. Hard cap of 50k rows per request keeps a runaway filter from holding a connection; the SPA narrows by date range when the cap clips. Response carries `Content-Type: text/csv; charset=utf-8` and `Content-Disposition: attachment; filename="audit-log.csv"` so the browser triggers a download. Column order matches what an operator typically pivots on in a spreadsheet review: when -> who -> what -> target -> network metadata (timestamp / actor / actor_id / action / entity_type / entity_id / entity_name / ip_address / user_agent). RFC-4180 quoting on any field containing a comma, quote, or newline. System-issued rows render the actor as `System` to match the SPA's table convention. This closes the audit / export half of PMS-455. The existing `/audit-log` JSON list + the `AuditCtx` helper writes from every privileged-action handler were already in place; this PR adds the export verb the original ticket called for. The client-side "Download CSV" button on `/admin/audit-log` lands in a sibling PR on mokosh-apps. #PMS-455
feat(audit): tenant-scoped CSV export endpoint (PMS-455)
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 1m15s
E2E / Playwright against staging (pull_request) Successful in 1m2s
Integration / integration tests (pull_request) Successful in 4m3s
Create release / Create release from merged PR (pull_request) Successful in 3s
a6f764e97c
`GET /api/v1/audit-log/export.csv` streams the same admin-gated, tenant-scoped audit-log feed `GET /audit-log` already exposes, but as a CSV download instead of a paginated JSON page. Same `AuditLogFilter` envelope (date range / action / entity-type / actor) so an operator can scope the export to whatever they were reviewing in the SPA. Hard cap of 50k rows per request keeps a runaway filter from holding a connection; the SPA narrows by date range when the cap clips.

Response carries `Content-Type: text/csv; charset=utf-8` and `Content-Disposition: attachment; filename="audit-log.csv"` so the browser triggers a download. Column order matches what an operator typically pivots on in a spreadsheet review: when -> who -> what -> target -> network metadata (timestamp / actor / actor_id / action / entity_type / entity_id / entity_name / ip_address / user_agent). RFC-4180 quoting on any field containing a comma, quote, or newline. System-issued rows render the actor as `System` to match the SPA's table convention.

This closes the audit / export half of PMS-455. The existing `/audit-log` JSON list + the `AuditCtx` helper writes from every privileged-action handler were already in place; this PR adds the export verb the original ticket called for. The client-side "Download CSV" button on `/admin/audit-log` lands in a sibling PR on mokosh-apps.

#PMS-455
YousifShkara deleted branch feat/PMS-455-audit-log-csv-export 2026-06-23 07:32:03 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!333
No description provided.