Skip to content

Improve auditlog table and model#3776

Open
Simrayz wants to merge 4 commits intomasterfrom
feat/3757-improve-auditlog-table-and-model
Open

Improve auditlog table and model#3776
Simrayz wants to merge 4 commits intomasterfrom
feat/3757-improve-auditlog-table-and-model

Conversation

@Simrayz
Copy link
Contributor

@Simrayz Simrayz commented Feb 10, 2026

Scope and purpose

Resolves #3757

Adds sortable display name columns (actor_sortkey, object_sortkey, target_sortkey) to auditlog entries. This enables sorting and searching on these columns, and allows showing entity links when the referenced objects still exist.

Key decisions:

  • Sortkeys preserve display names after objects are deleted
  • Batch resolution pattern loads entities without causing N+1 queries
  • Created API v2 to add entity linking while maintaining v1 backward compatibility

API v2 added: New /api/2/auditlog/ endpoint returns actor, object, and target as objects with {name, url} for entity linking. The existing /api/1/auditlog/ endpoint continues to return plain strings and remains unchanged. The web UI now uses v2.

Migration note: The backfill operation may take some time on deployments with millions of log entries.

Testing backfill and entity links

Filter by verb=edit-account-add-org, verb=disable-interface, verb=create-netbox, verb=delete-netbox, or verb=create-account to observe:

  • Clickable links when entities still exist - The actor/object/target names are clickable and navigate to the entity's detail page (e.g., clicking an account name goes to the account detail page)
  • Placeholder text when entities are deleted - Shows model_name (ID) format (e.g., account (123)) since the object no longer exists, but the sortkey preserved the searchable text

Contributor Checklist

Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.

  • Added a changelog fragment for towncrier
  • Added/amended tests for new/changed code
  • Added/changed documentation
  • Linted/formatted the code with ruff, easiest by using pre-commit
  • Wrote the commit message so that the first line continues the sentence "If applied, this commit will ...", starts with a capital letter, does not end with punctuation and is 50 characters or less long. See https://cbea.ms/git-commit/
  • Based this pull request on the correct upstream branch: For a patch/bugfix affecting the latest stable version, it should be based on that version's branch (<major>.<minor>.x). For a new feature or other additions, it should be based on master.
  • If applicable: Created new issues if this PR does not fix the issue completely/there is further work to be done
  • If it's not obvious from a linked issue, described how to interact with NAV in order for a reviewer to observe the effects of this change first-hand (commands, URLs, UI interactions)
  • If this results in changes in the UI: Added screenshots of the before and after
  • If this adds a new Python source code file: Added the boilerplate header to that file

@github-actions
Copy link

github-actions bot commented Feb 10, 2026

Test results

    21 files      21 suites   25m 19s ⏱️
 2 948 tests  2 948 ✅ 0 💤 0 ❌
16 476 runs  16 476 ✅ 0 💤 0 ❌

Results for commit 35e0dc7.

♻️ This comment has been updated with latest results.

@codecov
Copy link

codecov bot commented Feb 10, 2026

Codecov Report

❌ Patch coverage is 92.30769% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.33%. Comparing base (936bb62) to head (35e0dc7).
⚠️ Report is 27 commits behind head on master.

Files with missing lines Patch % Lines
python/nav/auditlog/api.py 91.66% 7 Missing ⚠️
python/nav/models/manage.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3776      +/-   ##
==========================================
+ Coverage   63.23%   63.33%   +0.10%     
==========================================
  Files         617      618       +1     
  Lines       45662    45813     +151     
  Branches       43       43              
==========================================
+ Hits        28874    29016     +142     
- Misses      16778    16787       +9     
  Partials       10       10              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from dc7d813 to af7aade Compare February 11, 2026 09:09
Add actor_sortkey, object_sortkey, and target_sortkey columns to
the auditlog_logentry table. These store the human-readable display
name at write time, enabling efficient database-level sorting and
searching, and preserving display names after referenced objects
are deleted.
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch 2 times, most recently from 56f4174 to 0d458cb Compare February 12, 2026 11:45
@Simrayz Simrayz requested a review from a team February 12, 2026 12:32
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from d4445f6 to 3837d41 Compare February 12, 2026 12:34
@Simrayz Simrayz marked this pull request as ready for review February 12, 2026 12:35
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from 3837d41 to 878e419 Compare February 12, 2026 12:58
@Simrayz Simrayz force-pushed the feat/3757-improve-auditlog-table-and-model branch from 878e419 to 35e0dc7 Compare February 12, 2026 13:15
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal to make our current auditlog much easier to deal with

1 participant