Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add models and admin integration for audit logging #71

Merged
merged 5 commits into from
Oct 10, 2024

Conversation

sergei-maertens
Copy link
Contributor

@sergei-maertens sergei-maertens commented Oct 9, 2024

Partially closes #16

Changes

  • Added dependency
  • Added base constraints/assumptions in proxy model for structured data logging
  • Added admin customizations

TODO

  • Add tests :-)

Preview:

image

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

Attention: Patch coverage is 97.82609% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/woo_publications/logging/models.py 96.15% 1 Missing and 2 partials ⚠️
Files with missing lines Coverage Δ
src/woo_publications/conf/base.py 95.00% <ø> (ø)
src/woo_publications/logging/admin.py 100.00% <100.00%> (ø)
src/woo_publications/logging/constants.py 100.00% <100.00%> (ø)
src/woo_publications/logging/models.py 96.15% <96.15%> (ø)

@sergei-maertens sergei-maertens force-pushed the feature/16-add-audit-logging branch 2 times, most recently from 407c0ea to 3ee603b Compare October 9, 2024 19:54
* Added proxy model, which enforces that an event and acting user is
  specified in the metadata of the log record. This is not 100% idiot
  proof since bulk update queries etc. and direct timeline-logger
  usage allows circumventing these. Ideally we'd have some database
  constraints, but those can't be specified through a proxy model.
* Added a custom admin integration for the proxy model:
  - block writing to log records entirely, even for superusers
  - process the event/acting_user structured data to display it as nice
    columns
  - allow searching on the user details in the admin log page
* Added a custom default message template that can leverage the
  metadata constraints that are enforced.
Ensure that the base assumptions and functionality work as expected.
@sergei-maertens sergei-maertens force-pushed the feature/16-add-audit-logging branch 2 times, most recently from e48c0f4 to d385ffd Compare October 10, 2024 08:27
@sergei-maertens sergei-maertens marked this pull request as ready for review October 10, 2024 08:27
@sergei-maertens sergei-maertens force-pushed the feature/16-add-audit-logging branch from d385ffd to 759a90c Compare October 10, 2024 09:03
log.content_object cannot be prefetch in Django 4.2 (though it looks
like 5.2 will have it). To avoid doing a query for each log record on a
page in the admin list (100 records -> 100 queries), we can cache the
representation and make sure we try the cache first before doing extra
queries.
@sergei-maertens sergei-maertens force-pushed the feature/16-add-audit-logging branch from 759a90c to e797ba5 Compare October 10, 2024 09:19
@sergei-maertens sergei-maertens merged commit 11343bf into main Oct 10, 2024
18 checks passed
@sergei-maertens sergei-maertens deleted the feature/16-add-audit-logging branch October 10, 2024 09:38
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.

ODRC: Set up foundation for logging/audit trails
2 participants