Skip to content

Commit 2ba571d

Browse files
authored
Attach org to impersonation return (calcom#24012)
1 parent 4a0a1ef commit 2ba571d

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CredentialsProvider from "next-auth/providers/credentials";
33
import { z } from "zod";
44

55
import { ensureOrganizationIsReviewed } from "@calcom/ee/organizations/lib/ensureOrganizationIsReviewed";
6+
import { getOrgFullOrigin, subdomainSuffix } from "@calcom/ee/organizations/lib/orgDomains";
67
import { getSession } from "@calcom/features/auth/lib/getSession";
78
import { getSpecificPermissions } from "@calcom/features/pbac/lib/resource-permissions";
89
import { ProfileRepository } from "@calcom/lib/server/repository/profile";
@@ -53,6 +54,8 @@ const auditAndReturnNextUser = async (
5354
},
5455
});
5556

57+
const profileOrg = impersonatedUser.profile?.organization;
58+
5659
const obj = {
5760
id: impersonatedUser.id,
5861
username: impersonatedUser.username,
@@ -63,6 +66,18 @@ const auditAndReturnNextUser = async (
6366
organizationId: impersonatedUser.organizationId,
6467
locale: impersonatedUser.locale,
6568
profile: impersonatedUser.profile,
69+
// Add org object if the user belongs to an organization
70+
...(profileOrg && {
71+
org: {
72+
id: profileOrg.id,
73+
name: profileOrg.name,
74+
slug: profileOrg.slug || "",
75+
logoUrl: profileOrg.logoUrl,
76+
fullDomain: getOrgFullOrigin(profileOrg.slug || ""),
77+
domainSuffix: subdomainSuffix(),
78+
role: profileOrg.members?.[0]?.role || MembershipRole.MEMBER,
79+
},
80+
}),
6681
};
6782

6883
if (!isReturningToSelf) {

0 commit comments

Comments
 (0)