Skip to content

feat: Add AdminAuditLog model with read-only admin view#388

Open
mayasimi wants to merge 2 commits intoSoroScan:mainfrom
mayasimi:main
Open

feat: Add AdminAuditLog model with read-only admin view#388
mayasimi wants to merge 2 commits intoSoroScan:mainfrom
mayasimi:main

Conversation

@mayasimi
Copy link
Copy Markdown

close #360

Summary

Adds a dedicated AdminAuditLog model to track every create, update, and delete action performed through the Django Admin interface, with a read-only view to inspect the audit trail.

What changed

New AdminAuditLog model — immutable, append-only, stores user, action type, affected object, IP address, and timestamp. Attempts to update or delete a record raise ValidationError.
Updated AdminAuditMixin._audit() to write to AdminAuditLog on every admin add/change/delete, in addition to the existing AdminAction log.
AdminAuditLogAdmin registered as a fully read-only view with color-coded action display, date hierarchy, search, and filters.
Migration 0037_adminauditlog with composite indexes on (action, timestamp), (content_type, object_id), and (user, timestamp).
Tests

28 new tests covering:

Model immutability (no updates, no deletes)
Mixin logs create, update, and delete correctly
IP extraction from REMOTE_ADDR and X-Forwarded-For
Anonymous user stored as null
Admin view has no add/change/delete permissions
All fields are read-only
Color-coded action display
Result: 463 passed, 5 skipped (pre-existing hypothesis env issue, unrelated)

Acceptance criteria met

AdminAuditLog model created
All admin changes logged (create, update, delete)
Includes user, action, and timestamp
Audit log viewable in admin (read-only)
Tests verify audit logging

… coverage

- Add AdminAuditLog model (immutable, append-only) tracking create/update/delete
  actions with user, action type, object repr, content_type, object_id, IP, timestamp
- Add migration 0037_adminauditlog with composite indexes
- Update AdminAuditMixin._audit() to write to both AdminAction and AdminAuditLog
- Register AdminAuditLogAdmin as read-only view with colored action display,
  date_hierarchy, search, and list filters
- Add AdminAuditLogFactory to test factories
- Add 28 tests covering model immutability, mixin logging (add/change/delete),
  IP extraction (direct + X-Forwarded-For), anonymous user handling,
  admin permissions, and colored display
- Update test_migration_graph.py leaf node assertion to 0037_adminauditlog
@DokaIzk
Copy link
Copy Markdown
Contributor

DokaIzk commented Apr 28, 2026

@mayasimi Please resolve conflicts

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 28, 2026

@mayasimi Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@mayasimi
Copy link
Copy Markdown
Author

@DokaIzk Resolved

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.

Log all admin user actions (create, edit, delete) to audit table

2 participants