From 5ba0ee8e85eb5b285a12c498274b9b45effd9665 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Wed, 28 Feb 2024 12:16:46 +0000 Subject: [PATCH] fix: impersonation detecting orgs correctly. (#13889) * feat:fix correctly detect impersonation organization * chore: remove logs * Update packages/features/ee/impersonation/lib/ImpersonationProvider.ts --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> --- .../features/ee/impersonation/lib/ImpersonationProvider.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/features/ee/impersonation/lib/ImpersonationProvider.ts b/packages/features/ee/impersonation/lib/ImpersonationProvider.ts index 0a70bad259..ddfa575241 100644 --- a/packages/features/ee/impersonation/lib/ImpersonationProvider.ts +++ b/packages/features/ee/impersonation/lib/ImpersonationProvider.ts @@ -198,6 +198,7 @@ async function isReturningToSelf({ session, creds }: { session: Session | null; role: true, organizationId: true, locale: true, + profiles: true, teams: { where: { accepted: true, // Ensure they are apart of the team and not just invited. @@ -213,7 +214,10 @@ async function isReturningToSelf({ session, creds }: { session: Session | null; if (returningUser) { // Skip for none org users - if (returningUser.role !== "ADMIN" && !returningUser.organizationId) return; + const inOrg = + returningUser.organizationId || // Keep for backwards compatability + returningUser.profiles.some((profile) => profile.organizationId !== undefined); // New way of seeing if the user has a profile in orgs. + if (returningUser.role !== "ADMIN" && !inOrg) return; const hasTeams = returningUser.teams.length >= 1;