Skip to content

fix(api): move recent-actions LogEntry query into audit.py (test_s15 red on main)#525

Closed
MartinCastroAlvarez wants to merge 1 commit into
mainfrom
fix/recent-actions-s15-queryset
Closed

fix(api): move recent-actions LogEntry query into audit.py (test_s15 red on main)#525
MartinCastroAlvarez wants to merge 1 commit into
mainfrom
fix/recent-actions-s15-queryset

Conversation

@MartinCastroAlvarez
Copy link
Copy Markdown
Owner

Summary

tests/test_security.py::test_s15_no_objects_all_or_filter_in_api is currently red on main: #505 inlined LogEntry.objects.filter(user__pk=…) in django_admin_react/api/views/recent_actions.py, violating the hard invariant that no Model.objects.all|filter appears under api/ (SECURITY §3 rule 10 / ACCEPTANCE B-2). It merged green because only CodeQL gates server-side — precisely the regression class #452 is about.

Fix

Move the query into django_admin_react/audit.py — the module that exists specifically to hold LogEntry access outside api/ (LogEntry is Django's own audit table, not a consumer model, so get_queryset is inapplicable; but the query still doesn't belong in the consumer-model API layer). Add user_log_entries(user_pk, limit) beside the existing object_log_entries, and call it from the view.

Pure refactor — identical query (user__pk, -action_time, sliced to limit); no behavior change.

Tier

Tier 2/3 — restores a security invariant; backend only, no auth/CSRF surface change.

Verification

  • pytest tests/test_security.py::test_s15… tests/test_recent_actions.py13 passed (the security test goes green; all 12 recent-actions tests unchanged).
  • ruff check + flake8 clean on both changed files.

This makes main pass its own security suite again (and unblocks the backend job in the CI PR #506).

🤖 Generated with Claude Code

#505 inlined `LogEntry.objects.filter(user__pk=...)` in
`api/views/recent_actions.py`, which trips the security invariant
`tests/test_security.py::test_s15_no_objects_all_or_filter_in_api`
(SECURITY §3 rule 10 / ACCEPTANCE B-2: no `Model.objects.all|filter`
under `api/`). It merged green because only CodeQL gates server-side —
exactly the regression class #452 is about — so `test_s15` has been red
on `main`.

`audit.py` exists precisely to hold LogEntry access *outside* `api/`
(LogEntry is Django's own audit table, not a consumer model, so the
get_queryset rule is inapplicable — but the query still belongs out of
the consumer-model API layer). Add `user_log_entries(user_pk, limit)`
there, alongside the existing `object_log_entries`, and call it from the
view. Pure refactor — identical query (`user__pk`, newest-first, sliced).

Verified: `test_s15` + all 12 `test_recent_actions` pass; ruff + flake8
clean on both files.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@MartinCastroAlvarez
Copy link
Copy Markdown
Owner Author

Superseded by #523 (merged) — same fix (move the recent-actions LogEntry query out of api/ to satisfy S-15). The swarm landed it first; closing this duplicate. main is green on test_s15 again.

@MartinCastroAlvarez MartinCastroAlvarez deleted the fix/recent-actions-s15-queryset branch May 27, 2026 23:31
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.

2 participants