Skip to content

feat: add configurable scopes to the admin audit log #543 - #597

Open
kryachkow wants to merge 1 commit into
developmentfrom
543-improvements-to-the-admin-audit-log
Open

kryachkow wants to merge 1 commit into
developmentfrom
543-improvements-to-the-admin-audit-log

Conversation

@kryachkow

Copy link
Copy Markdown
Contributor

Applicable issues

Description of changes

The admin audit log had three rough edges: no-op channel updates produced empty-diff records (a #528 regression), the data_source block still showed up in dataset update diffs, and high-value operations (reindexing, dataset↔channel linking) weren't recorded at all. This PR addresses all three by introducing audit scopes.

  • Configurable scopes. Adds an AuditScope enum (config, ex_im, reindex, ds_link) and a scope column on audit_logs. Which scopes are recorded is controlled by a new AUDIT_SCOPE setting (default config,ex_im); the verbose reindex and ds_link scopes are opt-in per environment. This supersedes the single DETAILED_AUDIT boolean proposed in the issue with a more granular, per-scope toggle.
  • New event coverage. Channel reindexing and dataset↔channel linking are now audited via a new event-based logging path for operations that have no Auditable domain object.
  • No-op updates skipped. Config updates that don't change state (e.g. re-importing an unchanged channel) no longer produce empty-diff records; the latest same-scope state is compared before persisting.
  • Cleaner diffs. Obsolete keys such as data_source are stripped from historical state at read time, so they no longer appear in before/after diffs — without mutating the immutable audit rows.
  • Filtering. The audit log list/export API gains a scope filter.
  • Migration. Adds the scope column and backfills existing import/export records to ex_im (temporarily disabling the row-immutability trigger for the one-time backfill).

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Introduce an AuditScope enum (config, ex_im, reindex, ds_link) and a
scope column on audit_logs so verbose event auditing can be enabled per
environment. The AUDIT_SCOPE setting (default config,ex_im) controls
which scopes are recorded; writes for disabled scopes are skipped.

- Migration adds the scope column and backfills existing import_job rows
  to ex_im (toggling the immutability trigger for the one-time update).
- AuditService.persist/persist_batch are now async and gain a log_event
  method for events without an Auditable object (dataset linking,
  reindexing).
- Skip no-op config updates by comparing against the latest same-scope
  state, avoiding empty-diff records on unchanged re-imports.
- Add scope filtering to the audit log API/service and sanitize obsolete
  state keys at read time without mutating immutable rows.
@kryachkow kryachkow linked an issue Aug 17, 2026 that may be closed by this pull request
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.

Improvements to the admin audit log

1 participant