Skip to content

Commit 7dbc888

Browse files
fix: End Impersonation Without Logging Out Admin (calcom#25395)
Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com>
1 parent 8fcbf2c commit 7dbc888

2 files changed

Lines changed: 9 additions & 19 deletions

File tree

packages/features/ee/impersonation/components/ImpersonatingBanner.tsx

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,21 @@ function ImpersonatingBanner({ data }: ImpersonatingBannerProps) {
1212
if (!data?.user.impersonatedBy) return null;
1313
const returnToId = data.user.impersonatedBy.id;
1414

15-
const canReturnToSelf = data.user.impersonatedBy.role == "ADMIN" || data.user?.org?.id;
16-
1715
return (
1816
<>
1917
<TopBanner
2018
text={t("impersonating_user_warning", { user: data.user.orgAwareUsername || data.user.username })}
2119
variant="warning"
2220
actions={
23-
canReturnToSelf ? (
24-
<form
25-
onSubmit={(e) => {
26-
e.preventDefault();
27-
signIn("impersonation-auth", { returnToId });
28-
}}>
29-
<button className="text-emphasis hover:underline" data-testid="stop-impersonating-button">
30-
{t("impersonating_stop_instructions")}
31-
</button>
32-
</form>
33-
) : (
34-
<a className="border-b border-b-black" href="/auth/logout">
21+
<form
22+
onSubmit={(e) => {
23+
e.preventDefault();
24+
signIn("impersonation-auth", { returnToId });
25+
}}>
26+
<button className="text-emphasis hover:underline" data-testid="stop-impersonating-button">
3527
{t("impersonating_stop_instructions")}
36-
</a>
37-
)
28+
</button>
29+
</form>
3830
}
3931
/>
4032
</>

packages/features/ee/impersonation/lib/ImpersonationProvider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,13 +301,11 @@ async function isReturningToSelf({ session, creds }: { session: Session | null;
301301
});
302302

303303
if (returningUser) {
304-
// Skip for none org users
305304
const inOrg =
306305
returningUser.organizationId || // Keep for backwards compatibility
307306
returningUser.profiles.some((profile) => profile.organizationId !== undefined); // New way of seeing if the user has a profile in orgs.
308-
if (returningUser.role !== UserPermissionRole.ADMIN && !inOrg) return;
309-
310307
const hasTeams = returningUser.teams.length >= 1;
308+
if (returningUser.role !== UserPermissionRole.ADMIN && !inOrg && !hasTeams) return;
311309

312310
const profile = await findProfile(returningUser);
313311
return {

0 commit comments

Comments
 (0)