Show the impersonator in the admin header, not the impersonated user - #101
Draft
davegaeddert wants to merge 1 commit into
Draft
Show the impersonator in the admin header, not the impersonated user#101davegaeddert wants to merge 1 commit into
davegaeddert wants to merge 1 commit into
Conversation
The account menu in the admin's top right acts on the real, logged-in account (App Settings, Log out), but it rendered the impersonated user's avatar while impersonation was active — the request user is swapped by ImpersonateMiddleware. Render the impersonator's avatar there instead, and list "Impersonating <user>" plus a "Stop impersonating" item in the menu so the swap is still visible from inside the admin. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Cg1pujFBAeTeMgeLjMYFHm
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.
The account menu in the admin's top right acts on the real, logged-in account (App Settings, Log out), but it rendered the impersonated user's avatar while impersonation was active —
ImpersonateMiddlewareswaps the request user, and the header readsuserstraight from the template context.Changes
AdminView.get_template_contextnow putsimpersonator(the real user, orNone) in the context, matching what the toolbar item already does.admin/_header.htmlrenders the avatar forimpersonator or user, so the menu's face matches the account it acts on.Impersonating <user>with a "Stop impersonating" item (the toolbar's existing banner is unchanged).## Impersonatesection ofplain-admin/README.md.Testing
test_admin_header_shows_the_impersonator_not_the_impersonated_userinplain-admin/tests/public/test_impersonate.py— asserts the impersonator's avatar URL is in the page, the impersonated user's is not, and the stop item is present. Verified it fails without the template change.Usergained aget_avatar_url()so the header's avatar branch is actually exercised../scripts/test plain-admin(35 passed),./scripts/type-check plain-adminclean,ruff check/ruff formatclean. The oxlint step of./scripts/fixcouldn't download its binary in this sandbox; no JS/CSS was changed.Note (not changed here)
pinned_slugs/get_nav_tabsstill key pinned nav items off the request user, so pinned tabs come from the impersonated user's account while impersonating. Left alone as a separate question from the avatar.Generated by Claude Code