refactor: consolidate audit-log code into dojo/auditlog/ package#14763
refactor: consolidate audit-log code into dojo/auditlog/ package#14763Maffooch wants to merge 1 commit intoDefectDojo:devfrom
Conversation
Move dojo/auditlog.py (1,083 lines), dojo/pghistory_models.py, and
dojo/pghistory_utils.py into a self-contained dojo/auditlog/ package
that mirrors the dojo/url/ canonical layout from CLAUDE.md. Also pulls
in the action_history view, its template, and the LogEntryFilter /
PgHistoryFilter that previously lived in dojo/views.py, dojo/templates/,
and dojo/filters.py.
Layout:
- models.py DojoEvents proxy model (app_label dropped, auto-inferred)
- services.py pghistory registration, retention/cleanup, config
- helpers.py display formatting + Celery context wrappers
- backfill.py backfill subsystem (used by migrations + commands)
- filters.py LogEntryFilter, PgHistoryFilter
- settings.py env-var schema + pghistory field defaults (source of truth)
- ui/views.py action_history view
- ui/urls.py action_history route (name preserved)
- templates/dojo/action_history.html
Backward-compatible re-exports stay at dojo/pghistory_models.py,
dojo/pghistory_utils.py, and dojo/filters.py per the playbook, so the
21 existing call sites keep working without churn. dojo/auditlog.py and
the original template are deleted (the package replaces the file).
Notable details:
- __init__.py uses PEP 562 lazy attribute resolution. settings.dist.py
imports dojo.auditlog.settings at Django settings-load time, before
django.conf.settings is built; eager re-exports would pull in
django-dependent submodules and circularly import settings.
- DojoEvents drops the explicit app_label = "dojo" per CLAUDE.md
("DO NOT set app_label in Meta — auto-inferred"). makemigrations
--check reports zero new migrations.
- Defensive try/except blocks in services and backfill are dropped per
the user's directive — let pgtrigger / COPY failures surface loudly
rather than silently swallowing them.
- settings.dist.py becomes a consumer of dojo.auditlog.settings:
imports the env-schema dict (splatted into environ.Env via
**AUDITLOG_ENV_SCHEMA), the three PGHISTORY_*_FIELD constants, and
AUDITLOG_DISABLE_ON_RAW_SAVE; adds dojo/auditlog/templates to
TEMPLATES[0]["DIRS"] since auditlog isn't a separate Django app.
- unittests/test_auditlog.py: two @patch targets updated from
dojo.auditlog.call_command to dojo.auditlog.services.call_command,
reflecting where the import now lives.
Verified end-to-end against the running stack:
- python manage.py check -> no issues
- python manage.py makemigrations --check -> No changes detected
- unittests.test_auditlog -> 7/7 pass
- unittests.test_importers_performance -> 10/10 pass
- reverse('action_history', cid=1, oid=2) -> /history/1/2
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
8e38aad to
5f7e0b0
Compare
valentijnscholten
left a comment
There was a problem hiding this comment.
Defensive try/except blocks in services and backfill are intentionally dropped — let pgtrigger / COPY failures surface loudly rather than silently swallowing them.
Why are these being dropped? In case of some unexpected error this would block users from starting their instances after an upgrade.
|
I went back and looked at each spot to make sure the upgrade path wouldn't blow up, and I think we are actually safe here. For For the outer try/catch around The one real behavior change is in the manual |
Summary
dojo/auditlog.py(1,083 lines),dojo/pghistory_models.py, anddojo/pghistory_utils.pyinto a self-containeddojo/auditlog/package that mirrors thedojo/url/canonical layout fromCLAUDE.md.action_history), its template, andLogEntryFilter/PgHistoryFilterinto the package — they previously lived indojo/views.py,dojo/templates/, anddojo/filters.py.dojo/auditlog/settings.pybecomes the source of truth for the audit-log env-var schema and pghistory field defaults;settings.dist.pyimports from it.Layout
Notable details
__init__.pyuses PEP 562 lazy attribute resolution.settings.dist.pyimportsdojo.auditlog.settingsat Django settings-load time, beforedjango.conf.settingsis built; eager re-exports would circularly pull in django-dependent submodules.DojoEventsdrops the explicitapp_label = "dojo"perCLAUDE.md("DO NOT setapp_labelin Meta — auto-inferred").makemigrations --checkreports zero new migrations.try/exceptblocks in services and backfill are intentionally dropped — letpgtrigger/COPYfailures surface loudly rather than silently swallowing them.dojo/settings/settings.dist.pybecomes a consumer ofdojo.auditlog.settings: imports the env-schema dict (splatted intoenviron.Envvia**AUDITLOG_ENV_SCHEMA), the threePGHISTORY_*_FIELDconstants, andAUDITLOG_DISABLE_ON_RAW_SAVE; addsdojo/auditlog/templatestoTEMPLATES[0][\"DIRS\"]sincedojo.auditlogisn't a separate Django app.unittests/test_auditlog.py: two@patchtargets updated fromdojo.auditlog.call_commandtodojo.auditlog.services.call_command, reflecting where the import now lives.Out of scope (deferred per playbook)
dojo/test/signals.pyetc.) intodojo/auditlog/signals.py— they're domain-coupled by design.django-auditloglibrary;LogEntryFilterstill references it for the page's "legacy entries" pane.Test plan
python manage.py check— no issuespython manage.py makemigrations --check—No changes detected(the critical migration gate)unittests.test_auditlog— 7/7 passunittests.test_importers_performance— 10/10 passreverse('action_history', cid=1, oid=2)— resolves to/history/1/2(route name preserved)/history/<cid>/<oid>; confirm template renders, filters work (event type, user, IP, diff search), and a pghistory event is recorded withuser/url/remote_addr/source/scan_typecontext fields populated.🤖 Generated with Claude Code