fix: private link for a team event gives 404 (#14473)
## What does this PR do? Fixes #14456 https://github.com/calcom/cal.com/blob/65df5ac0e4086422bc0b8416f16ba991a10e785d/apps/web/lib/d/%5Blink%5D/%5Bslug%5D/getServerSideProps.tsx#L52-L60 For team events there is no username, so it was returning 404 irrespective of whether anyone was assigned or not. https://github.com/calcom/cal.com/assets/74371312/b4c8c592-4132-4040-acb2-db37f8f152d6 ## Type of change <!-- Please delete bullets that are not relevant. --> - Bug fix (non-breaking change which fixes an issue) ## Mandatory Tasks - [x] Make sure you have self-reviewed the code. A decent size PR without self-review might be rejected.
This commit is contained in:
@@ -42,6 +42,8 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
||||
team: {
|
||||
select: {
|
||||
id: true,
|
||||
slug: true,
|
||||
hideBranding: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -49,36 +51,53 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
||||
},
|
||||
});
|
||||
|
||||
const username = hashedLink?.eventType.users[0]?.username;
|
||||
let name: string;
|
||||
let isAway = false;
|
||||
let hideBranding = false;
|
||||
|
||||
const notFound = {
|
||||
notFound: true,
|
||||
} as const;
|
||||
|
||||
if (!hashedLink || !username) {
|
||||
if (!hashedLink) {
|
||||
return notFound;
|
||||
}
|
||||
|
||||
if (!org) {
|
||||
const redirect = await getTemporaryOrgRedirect({
|
||||
slugs: [username],
|
||||
redirectType: RedirectType.User,
|
||||
eventTypeSlug: slug,
|
||||
currentQuery: context.query,
|
||||
if (hashedLink.eventType.team) {
|
||||
name = hashedLink.eventType.team.slug || "";
|
||||
hideBranding = hashedLink.eventType.team.hideBranding;
|
||||
} else {
|
||||
const username = hashedLink.eventType.users[0]?.username;
|
||||
|
||||
if (!username) {
|
||||
return notFound;
|
||||
}
|
||||
|
||||
if (!org) {
|
||||
const redirect = await getTemporaryOrgRedirect({
|
||||
slugs: [username],
|
||||
redirectType: RedirectType.User,
|
||||
eventTypeSlug: slug,
|
||||
currentQuery: context.query,
|
||||
});
|
||||
|
||||
if (redirect) {
|
||||
return redirect;
|
||||
}
|
||||
}
|
||||
|
||||
const [user] = await UserRepository.findUsersByUsername({
|
||||
usernameList: [username],
|
||||
orgSlug: org,
|
||||
});
|
||||
|
||||
if (redirect) {
|
||||
return redirect;
|
||||
if (!user) {
|
||||
return notFound;
|
||||
}
|
||||
}
|
||||
|
||||
const [user] = await UserRepository.findUsersByUsername({
|
||||
usernameList: [username],
|
||||
orgSlug: org,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return notFound;
|
||||
name = username;
|
||||
isAway = user.away;
|
||||
hideBranding = user.hideBranding;
|
||||
}
|
||||
|
||||
let booking: GetBookingType | null = null;
|
||||
@@ -90,7 +109,12 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
||||
|
||||
// We use this to both prefetch the query on the server,
|
||||
// as well as to check if the event exist, so we c an show a 404 otherwise.
|
||||
const eventData = await ssr.viewer.public.event.fetch({ username, eventSlug: slug, isTeamEvent, org });
|
||||
const eventData = await ssr.viewer.public.event.fetch({
|
||||
username: name,
|
||||
eventSlug: slug,
|
||||
isTeamEvent,
|
||||
org,
|
||||
});
|
||||
|
||||
if (!eventData) {
|
||||
return notFound;
|
||||
@@ -105,11 +129,11 @@ async function getUserPageProps(context: GetServerSidePropsContext) {
|
||||
eventData.length
|
||||
),
|
||||
booking,
|
||||
away: user?.away,
|
||||
user: username,
|
||||
away: isAway,
|
||||
user: name,
|
||||
slug,
|
||||
trpcState: ssr.dehydrate(),
|
||||
isBrandingHidden: user?.hideBranding,
|
||||
isBrandingHidden: hideBranding,
|
||||
// Sending the team event from the server, because this template file
|
||||
// is reused for both team and user events.
|
||||
isTeamEvent,
|
||||
|
||||
Reference in New Issue
Block a user