fix: platform org members cannot access their public booking page (#20821)

* fix: platform member event pages

* chore: update slots docs

* refactor: user repository call

* refactor: remove newline
This commit is contained in:
Lauris Skraucis authored and GitHub committed 2025-04-23 14:29:26 +03:00
1 parent f5217caef2
commit f31c45a153
7 files changed
+60 -13

No files matched your search

@@ -16,6 +16,8 @@ import { BookingStatus, RedirectType } from "@calcom/prisma/client";
import { getTemporaryOrgRedirect } from "@lib/getTemporaryOrgRedirect";
import { getUsersInOrgContext } from "@server/lib/[user]/getServerSideProps";
type Props = {
eventData: NonNullable<Awaited<ReturnType<typeof getPublicEvent>>>;
booking?: GetBookingType;
@@ -228,10 +230,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
}
}
const [user] = await UserRepository.findUsersByUsername({
usernameList: [username],
orgSlug: isValidOrgDomain ? currentOrgDomain : null,
});
const [user] = await getUsersInOrgContext([username], isValidOrgDomain ? currentOrgDomain : null);
if (!user) {
return {
@@ -240,6 +239,7 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
}
const org = isValidOrgDomain ? currentOrgDomain : null;
// We use this to both prefetch the query on the server,
// as well as to check if the event exist, so we can show a 404 otherwise.
const eventData = await EventRepository.getPublicEvent(
@@ -92,10 +92,10 @@ export const getServerSideProps: GetServerSideProps<UserPageProps> = async (cont
}
}
const usersInOrgContext = await UserRepository.findUsersByUsername({
const usersInOrgContext = await getUsersInOrgContext(
usernameList,
orgSlug: isValidOrgDomain ? currentOrgDomain : null,
});
isValidOrgDomain ? currentOrgDomain : null
);
const isDynamicGroup = usersInOrgContext.length > 1;
log.debug(safeStringify({ usersInOrgContext, isValidOrgDomain, currentOrgDomain, isDynamicGroup }));
@@ -197,3 +197,22 @@ export const getServerSideProps: GetServerSideProps<UserPageProps> = async (cont
},
};
};
export async function getUsersInOrgContext(usernameList: string[], orgSlug: string | null) {
const usersInOrgContext = await UserRepository.findUsersByUsername({
usernameList,
orgSlug,
});
if (usersInOrgContext.length) {
return usersInOrgContext;
}
// note(Lauris): platform members (people who run platform) are part of platform organization while
// the platform organization does not have a domain. In this case there is no org domain but also platform member
// "User.organization" is not null so "UserRepository.findUsersByUsername" returns empty array and we do this as a last resort
// call to find platform member.
return await UserRepository.findPlatformMembersByUsernames({
usernameList,
});
}