-
Notifications
You must be signed in to change notification settings - Fork 0
PR #614: Super-admin impersonation + /admin/users + /admin/audit-log #640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
barach6662001-bit
merged 8 commits into
main
from
feat/pr-614-super-admin-impersonation
Apr 25, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f18857e
docs(roadmap): correct currency conversion v2 PR number (#632 → #634)…
barach6662001-bit 041d0c1
chore(roadmap): split PR #614 into core + #614a (system) + #614b (cat…
barach6662001-bit 9e572ea
feat(impersonation): backend engine, JWT extension, forbidden-action …
barach6662001-bit 78378f1
feat(impersonation): add partial composite index for rate-limit query
barach6662001-bit 107071f
test(impersonation): 6 integration scenarios + extend TestAuthHandler…
barach6662001-bit fd45e6a
feat(frontend): super-admin impersonation banner + /admin/users + /ad…
barach6662001-bit 3c9a3cb
fix(impersonation): default-impl IsImpersonating/ImpersonatedByUserId…
barach6662001-bit 2002499
Merge branch 'main' into feat/pr-614-super-admin-impersonation
barach6662001-bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
108 changes: 108 additions & 0 deletions
108
frontend/src/components/Impersonation/ImpersonationBanner.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| import { useEffect, useState } from 'react'; | ||
| import { Button, message } from 'antd'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import { useAuthStore } from '../../stores/authStore'; | ||
| import { endImpersonation } from '../../api/admin'; | ||
| import { useTranslation } from '../../i18n'; | ||
|
|
||
| /** | ||
| * Persistent red banner shown while a super-admin is impersonating another user | ||
| * (PR #614). Per spec it is NOT closable / dismissable, sits above every other | ||
| * UI layer (z-index 9999), spans the full viewport width and exposes a single | ||
| * "exit" action that calls /api/admin/impersonate/end and restores the | ||
| * pre-impersonation super-admin token. | ||
| */ | ||
| export default function ImpersonationBanner() { | ||
| const { t } = useTranslation(); | ||
| const navigate = useNavigate(); | ||
| const impersonation = useAuthStore((s) => s.impersonation); | ||
| const setAuth = useAuthStore((s) => s.setAuth); | ||
| const clearImpersonation = useAuthStore((s) => s.clearImpersonation); | ||
|
|
||
| const [now, setNow] = useState<number>(() => Date.now()); | ||
| const [busy, setBusy] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (!impersonation) return; | ||
| const id = window.setInterval(() => setNow(Date.now()), 1000); | ||
| return () => window.clearInterval(id); | ||
| }, [impersonation]); | ||
|
|
||
| if (!impersonation) return null; | ||
|
|
||
| const expiresAt = new Date(impersonation.expiresAtUtc).getTime(); | ||
| const remainingMs = Math.max(0, expiresAt - now); | ||
| const totalSec = Math.floor(remainingMs / 1000); | ||
| const mm = Math.floor(totalSec / 60).toString().padStart(2, '0'); | ||
| const ss = (totalSec % 60).toString().padStart(2, '0'); | ||
|
|
||
| const onExit = async () => { | ||
| setBusy(true); | ||
| try { | ||
| // Best-effort server-side end. Even if it fails (e.g. token already | ||
| // expired) we still locally restore the original super-admin token. | ||
| try { | ||
| await endImpersonation(); | ||
| } catch { | ||
| /* ignore — local restore below is the source of truth */ | ||
| } | ||
| setAuth( | ||
| impersonation.originalToken, | ||
| impersonation.originalEmail, | ||
| impersonation.originalRole, | ||
| impersonation.originalTenantId, | ||
| false, | ||
| true, | ||
| impersonation.originalFirstName, | ||
| impersonation.originalLastName, | ||
| undefined, | ||
| true, | ||
| ); | ||
| clearImpersonation(); | ||
| navigate('/admin/users'); | ||
| } catch { | ||
| message.error(t.admin.bannerExitFailed); | ||
| } finally { | ||
| setBusy(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| role="alert" | ||
| aria-live="assertive" | ||
| style={{ | ||
| position: 'fixed', | ||
| top: 0, | ||
| left: 0, | ||
| right: 0, | ||
| width: '100vw', | ||
| zIndex: 9999, | ||
| background: '#b91c1c', | ||
| color: '#fff', | ||
| padding: '8px 16px', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'space-between', | ||
| gap: 12, | ||
| boxShadow: '0 2px 6px rgba(0,0,0,0.35)', | ||
| fontSize: 13, | ||
| }} | ||
| > | ||
| <div style={{ display: 'flex', alignItems: 'center', gap: 16, flexWrap: 'wrap' }}> | ||
| <strong style={{ letterSpacing: 0.3 }}> | ||
| {t.admin.bannerActiveAs}: {impersonation.targetEmail} ({impersonation.targetTenantName}) | ||
| </strong> | ||
| <span style={{ opacity: 0.9 }}> | ||
| {t.admin.bannerOriginal}: {impersonation.originalEmail} | ||
| </span> | ||
| <span style={{ opacity: 0.9 }}> | ||
| {t.admin.bannerExpiresIn}: {mm}:{ss} | ||
| </span> | ||
| </div> | ||
| <Button danger type="primary" size="small" loading={busy} onClick={onExit}> | ||
| {t.admin.bannerExit} | ||
| </Button> | ||
| </div> | ||
| ); | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After
POST /api/admin/impersonate/end, the code immediately restoresimpersonation.originalTokeninstead of using the fresh token returned by the backend. If the original token has expired during impersonation, the next API call fails with 401 even though/endsucceeded, causing an avoidable forced re-login path; the exit flow should apply the response token as the source of truth.Useful? React with 👍 / 👎.