Skip to content

feat(users): add token-swap impersonation for superusers - #152

Draft
geourjoa wants to merge 2 commits into
mainfrom
feat-6/user-impersonation
Draft

feat(users): add token-swap impersonation for superusers#152
geourjoa wants to merge 2 commits into
mainfrom
feat-6/user-impersonation

Conversation

@geourjoa

@geourjoa geourjoa commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

WIP

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).
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.
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.

1 participant