Skip to content

[Site Admin] Site admin audit log read API#5790

Open
carmenlau wants to merge 9 commits into
authgear:mainfrom
carmenlau:dev-3549-siteadmin-audit-log
Open

[Site Admin] Site admin audit log read API#5790
carmenlau wants to merge 9 commits into
authgear:mainfrom
carmenlau:dev-3549-siteadmin-audit-log

Conversation

@carmenlau

Copy link
Copy Markdown
Contributor

ref DEV-3549

Add GET /api/v1/audit-logs and GET /api/v1/audit-logs/:id endpoints to the site admin API for querying site admin audit log entries.

  • Filter by affected app (affected_app_id)
  • Sort direction (order=asc|desc, defaults to desc)
  • Offset-based pagination (page, page_size, max 100)
  • Detail endpoint returns the full raw data field

carmenlau and others added 9 commits June 24, 2026 14:11
SiteAdminAuditLogStore queries _audit_log scoped to the portal app ID.
Count/List/Get each build a Squirrel query with activity_type LIKE
'site_admin.%', an optional affected_app_id JSON path filter, and
ORDER BY created_at DESC/ASC driven by the order parameter.

SiteAdminAuditReadService wraps the store with a nil-DB guard and
pagination normalisation (page defaults to 1, page_size clamped to 100,
order defaults to desc when invalid).

ref DEV-3549
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Define AuditLogsListService and AuditLogGetService narrow interfaces on
the two handler structs. parseAuditLogsListParams reads page, page_size,
affected_app_id, and order from the query string. ServeHTTP bodies are
stubs (http.NotFound) pending DI wiring.

ref DEV-3549
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add SiteAdminAuditReadDatabase interface binding (*auditdb.ReadHandle),
SiteAdminAuditLogStoreIface binding, and transport bindings for
AuditLogsListService and AuditLogGetService. Regenerate wire_gen.go.

ref DEV-3549
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
AuditLogsListHandler calls ListAuditLogs and maps entries to
SiteAdminAuditLog using the entryToSiteAdminAuditLog helper (defined in
handler_audit_logs_list.go and shared with AuditLogGetHandler).
AuditLogGetHandler calls GetAuditLog and returns SiteAdminAuditLogDetail
including the raw data field.

Add vettedpositions for r.Context() in both handlers. Apply make
check-tidy formatting output.

ref DEV-3549
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ref DEV-3549
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Seed 3 known entries directly via custom_audit_sql fixture
(seed_siteadmin_audit_logs.sql) using a dedicated app ID
(e2e-audit-log-app) that no other test touches.

Tests cover:
- GET /api/v1/audit-logs: basic structure, affected_app_id filter,
  order=desc (newest first), order=asc (oldest first), pagination
- GET /api/v1/audit-logs/:id: detail response with data field
- GET /api/v1/audit-logs/non-existent: 404

ref DEV-3549
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@carmenlau carmenlau requested a review from tung2744 June 24, 2026 21:45
@carmenlau carmenlau changed the title [Site Admin] Site Admin Audit log read API [Site Admin] Site admin audit log read API Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants