Skip to content

Feature/admin audit log UI - #443

Open
uche102 wants to merge 2 commits into
AetherEdu:mainfrom
uche102:feature/admin-audit-log-ui
Open

Feature/admin audit log UI#443
uche102 wants to merge 2 commits into
AetherEdu:mainfrom
uche102:feature/admin-audit-log-ui

Conversation

@uche102

@uche102 uche102 commented Aug 22, 2026

Copy link
Copy Markdown

Summary

Exposes the platform audit logging system (#135) through a dedicated Admin UI and RBAC-restricted API endpoints. Authorized administrators can search, filter, inspect event details (including before/after state changes), export filtered results in CSV or JSON format, and trigger log retention purging.


Acceptance Criteria Covered

  • Searchable & Filterable Audit Log: Search across actors, actions, resources, resource IDs, and date ranges.
  • Event Detail View: Modal displaying before/after state changes, request IP, user agent, and full metadata payload.
  • Audit Result Exports: Export filtered audit records directly as CSV or JSON file downloads.
  • Retention & Purging Controls: Configurable retention thresholds (30, 60, 90, 180, 365 days) with audit log purging.
  • RBAC Restricted: Endpoints and UI access strictly enforced via authenticate and requireAdmin middleware.

Key Implementation Details

1. Backend Service (backend/src/services/auditService.ts)

  • Search & Filtering: Added $regex text matching across actor, action, resource, resourceId, and error messages.
  • Exporting: Implemented exportLogs(options, format) producing formatted CSV or pretty-printed JSON output.
  • Retention Purging: Added purgeOldLogs(retentionDays) to delete audit entries older than the retention threshold.

2. Admin Query Routes (backend/src/routes/admin/audit.ts)

  • GET /api/admin/audit: Paginated, multi-field search and filter endpoints.
  • GET /api/admin/audit/stats: Aggregated metrics for success/failure rates and top actors.
  • GET /api/admin/audit/export: Triggers CSV or JSON download with Content-Disposition headers.
  • POST /api/admin/audit/purge: Retention purging action ({ retentionDays: number }).
  • GET /api/admin/audit/:id: Retrieves full details for a single audit event.
  • Mounted under /api/admin/audit and /api/v1/admin/audit in backend/src/index.ts.

3. Frontend Admin UI (frontend/src/app/admin/audit/page.tsx)

  • Metrics Summary Cards: Total entries, success operations, failure count, active actors.
  • Interactive Data Table: Color-coded badges for actions and status, timestamp formatting, pagination controls.
  • Event Detail Modal: Embedded syntax-highlighted viewer for inspecting before/after payload details.
  • Export & Retention Modals: Direct CSV/JSON file generation and a purge confirmation dialog.
  • Sidebar Integration: Added "Audit Logs" entry under Platform Operations in AdminSidebar.tsx.

Files Changed

  • backend/src/services/auditService.ts (Modified)
  • backend/src/routes/admin/audit.ts (New)
  • backend/src/index.ts (Modified)
  • frontend/src/app/admin/audit/page.tsx (New)
  • frontend/src/components/Admin/AdminSidebar.tsx (Modified)

How to Test

  1. Launch the backend and navigate to the admin audit endpoint or page:
    # Backend API
    GET /api/admin/audit?search=CREATE&result=success

-Closes #400

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.

[Frontend] Audit trail admin UI

1 participant