Skip to content

Show the impersonator in the admin header, not the impersonated user - #101

Draft
davegaeddert wants to merge 1 commit into
masterfrom
claude/impersonated-avatar-display-8flg0q
Draft

Show the impersonator in the admin header, not the impersonated user#101
davegaeddert wants to merge 1 commit into
masterfrom
claude/impersonated-avatar-display-8flg0q

Conversation

@davegaeddert

Copy link
Copy Markdown
Member

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 — ImpersonateMiddleware swaps the request user, and the header reads user straight from the template context.

Changes

  • AdminView.get_template_context now puts impersonator (the real user, or None) in the context, matching what the toolbar item already does.
  • admin/_header.html renders the avatar for impersonator or user, so the menu's face matches the account it acts on.
  • Because swapping the avatar would otherwise hide the impersonation from inside the admin, the dropdown now shows Impersonating <user> with a "Stop impersonating" item (the toolbar's existing banner is unchanged).
  • Docs: a note in the ## Impersonate section of plain-admin/README.md.

Testing

  • New test_admin_header_shows_the_impersonator_not_the_impersonated_user in plain-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.
  • The test app's User gained a get_avatar_url() so the header's avatar branch is actually exercised.
  • ./scripts/test plain-admin (35 passed), ./scripts/type-check plain-admin clean, ruff check/ruff format clean. The oxlint step of ./scripts/fix couldn't download its binary in this sandbox; no JS/CSS was changed.

Note (not changed here)

pinned_slugs / get_nav_tabs still 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

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