From 2ba571d2305453bf3f8ce4c4f54e6ab0cb8c8602 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Tue, 23 Sep 2025 19:34:16 +0100 Subject: [PATCH] Attach org to impersonation return (#24012) --- .../ee/impersonation/lib/ImpersonationProvider.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/features/ee/impersonation/lib/ImpersonationProvider.ts b/packages/features/ee/impersonation/lib/ImpersonationProvider.ts index bd9c340f5a..671acba3b4 100644 --- a/packages/features/ee/impersonation/lib/ImpersonationProvider.ts +++ b/packages/features/ee/impersonation/lib/ImpersonationProvider.ts @@ -3,6 +3,7 @@ import CredentialsProvider from "next-auth/providers/credentials"; import { z } from "zod"; import { ensureOrganizationIsReviewed } from "@calcom/ee/organizations/lib/ensureOrganizationIsReviewed"; +import { getOrgFullOrigin, subdomainSuffix } from "@calcom/ee/organizations/lib/orgDomains"; import { getSession } from "@calcom/features/auth/lib/getSession"; import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions"; import { ProfileRepository } from "@calcom/lib/server/repository/profile"; @@ -53,6 +54,8 @@ const auditAndReturnNextUser = async ( }, }); + const profileOrg = impersonatedUser.profile?.organization; + const obj = { id: impersonatedUser.id, username: impersonatedUser.username, @@ -63,6 +66,18 @@ const auditAndReturnNextUser = async ( organizationId: impersonatedUser.organizationId, locale: impersonatedUser.locale, profile: impersonatedUser.profile, + // Add org object if the user belongs to an organization + ...(profileOrg && { + org: { + id: profileOrg.id, + name: profileOrg.name, + slug: profileOrg.slug || "", + logoUrl: profileOrg.logoUrl, + fullDomain: getOrgFullOrigin(profileOrg.slug || ""), + domainSuffix: subdomainSuffix(), + role: profileOrg.members?.[0]?.role || MembershipRole.MEMBER, + }, + }), }; if (!isReturningToSelf) {