feat(users): add token-swap impersonation for superusers - #152
Draft
geourjoa wants to merge 2 commits into
Draft
Conversation
django-impersonate assumes session-based auth (middleware swaps
request.user via a cookie), but this project authenticates with DRF
TokenAuthentication against the stock auth.User model and has no
django.contrib.admin. Model that architecture instead: a superuser-gated
POST /api/v1/auth/management/users/{id}/impersonate/ action mints (or
reuses) the target's own DRF Token and returns it so the frontend can
swap its stored token to browse as that user.
Guards against impersonating yourself or another staff/superuser
account, and records actor/target/timestamp via the existing EditEvent
audit log (new "impersonated" action).
4 tasks
log_edit()'s action parameter is typed str, but this project has no django-stubs mypy plugin configured, so mypy sees EditEvent.Action.X class body assignments as raw tuple[str, str] literals rather than resolved enum members. apps/common/audit.py already works around this with cast(str, ...) at its two call sites; services.py's new call needed the same treatment. Also bumps cryptography>=49.0.0 -> >=50.0.0 (CI's dependency-audit job flags PYSEC-2026-3552 against 49.0.0, fixed in 50.0.0) — same fix as feat-1/feat-4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WIP