Files
Benny JooGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ab21c7f805 refactor: Cal.diy (#28903)
* feat: Cal.diy — community-driven MIT-licensed fork of Cal.com

This squashed commit contains all Cal.diy changes applied on top of calcom/cal.com main:

- Rebrand Cal.com to Cal.diy across the entire codebase
- Remove Enterprise Edition (EE) features, license checks, and AGPL restrictions
- Switch license from AGPL-3.0 to MIT
- Remove docs/ directory (migrated to Nextra at cal.diy)
- Remove dead code: org tests, EE tips, platform nav, premium username, SAML/SSO, etc.
- Clean up .env.example for self-hosted Cal.diy
- Update Docker image references to calcom/cal.diy
- Update README, CONTRIBUTING.md, and issue templates for Cal.diy community fork
- Add PR welcome bot for Cal.diy contributors
- Fix API v2 breaking changes oasdiff ignore entries
- Replace Blacksmith CI runners with default GitHub Actions

3893 files changed, 20789 insertions(+), 411020 deletions(-)

Co-Authored-By: [email protected] <[email protected]>

* refactor: remove org-specific /organizations/:orgId endpoints from API v2 atoms controllers (#1701)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: revert Cal.diy Inc to Cal.com, Inc. in license files, copyright notices, and package metadata (#1702)

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* rip out org related comments in api v2

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-04-15 09:52:36 -03:00

161 lines
5.4 KiB
TypeScript

import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import type { GetBookingType } from "@calcom/features/bookings/lib/get-booking";
import { getBookingForReschedule, getMultipleDurationValue } from "@calcom/features/bookings/lib/get-booking";
import { EventRepository } from "@calcom/features/eventtypes/repositories/EventRepository";
import { HashedLinkService } from "@calcom/features/hashedLink/lib/service/HashedLinkService";
import {
shouldHideBrandingForTeamEvent,
shouldHideBrandingForUserEvent,
} from "@calcom/features/profile/lib/hideBranding";
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
import slugify from "@calcom/lib/slugify";
import prisma from "@calcom/prisma";
import { RedirectType } from "@calcom/prisma/enums";
import { getRedirectWithOriginAndSearchString } from "@lib/handleOrgRedirect";
import type { inferSSRProps } from "@lib/types/inferSSRProps";
import type { EmbedProps } from "app/WithEmbedSSR";
import type { GetServerSidePropsContext } from "next";
import { z } from "zod";
export type PageProps = inferSSRProps<typeof getServerSideProps> & EmbedProps;
async function getUserPageProps(context: GetServerSidePropsContext) {
const session = await getServerSession({ req: context.req });
const { link, slug } = paramsSchema.parse(context.params);
const { rescheduleUid, duration: queryDuration } = context.query;
const currentOrgDomain = null;
const isValidOrgDomain = false;
const org = isValidOrgDomain ? currentOrgDomain : null;
let name: string;
let hideBranding = false;
const notFound = {
notFound: true,
} as const;
// Use centralized validation logic to avoid duplication
const hashedLinkService = new HashedLinkService();
try {
await hashedLinkService.validate(link);
} catch (_error) {
// Link is expired, invalid, or doesn't exist
return notFound;
}
// If validation passes, fetch the complete data needed for rendering
const hashedLink = await hashedLinkService.findLinkWithDetails(link);
if (!hashedLink) {
return notFound;
}
const username = hashedLink.eventType.users[0]?.username;
const profileUsername = hashedLink.eventType.users[0]?.profiles[0]?.username;
if (hashedLink.eventType.team) {
name = hashedLink.eventType.team.slug || "";
hideBranding = shouldHideBrandingForTeamEvent({
eventTypeId: hashedLink.eventTypeId,
team: hashedLink.eventType.team,
});
} else {
if (!username) {
return notFound;
}
// Get just the origin and searchString from the redirect to ensure that we don't redirect to a URL that exposes the real path to book the user for any other events \
// This is important for a private booking link
// e.g. http://app.cal.com/d/sgdthj8mu4nsLNTYi3fW2p/demo -> should redirect to -> http://acme.cal.com/d/sgdthj8mu4nsLNTYi3fW2p/demo and not to http://acme.cal.com/john/demo(which exposes the real path to book the user for any other events)
const redirectWithOriginAndSearchString = await getRedirectWithOriginAndSearchString({
slugs: [username],
redirectType: RedirectType.User,
context,
currentOrgDomain: isValidOrgDomain ? currentOrgDomain : null,
});
if (redirectWithOriginAndSearchString) {
return {
redirect: {
permanent: false,
// App Router doesn't have access to the current path directly, so we build it manually
destination: `${redirectWithOriginAndSearchString.origin ?? ""}/d/${link}/${slug}${
redirectWithOriginAndSearchString.searchString
}`,
},
};
}
name = profileUsername || username;
const userRepo = new UserRepository(prisma);
const [user] = await userRepo.findUsersByUsername({
usernameList: [name],
orgSlug: org,
});
if (!user) {
return notFound;
}
hideBranding = shouldHideBrandingForUserEvent({
eventTypeId: hashedLink.eventTypeId,
owner: user,
});
}
let booking: GetBookingType | null = null;
if (rescheduleUid) {
booking = await getBookingForReschedule(`${rescheduleUid}`, session?.user?.id);
}
const isTeamEvent = !!hashedLink.eventType?.team?.id;
const eventData = await EventRepository.getPublicEvent(
{
username: name,
eventSlug: slug,
isTeamEvent,
org,
fromRedirectOfNonOrgLink: context.query.orgRedirection === "true",
},
session?.user?.id
);
if (!eventData) {
return notFound;
}
const useApiV2 = false;
return {
props: {
useApiV2,
eventData,
entity: eventData.entity,
duration: getMultipleDurationValue(
eventData.metadata?.multipleDuration,
queryDuration,
eventData.length
),
durationConfig: eventData.metadata?.multipleDuration ?? [],
booking,
user: name,
slug,
isBrandingHidden: hideBranding,
// Sending the team event from the server, because this template file
// is reused for both team and user events.
isTeamEvent,
hashedLink: hashedLink?.link,
},
};
}
const paramsSchema = z.object({ link: z.string(), slug: z.string().transform((s) => slugify(s)) });
// Booker page fetches a tiny bit of data server side, to determine early
// whether the page should show an away state or dynamic booking not allowed.
export const getServerSideProps = async (context: GetServerSidePropsContext) => {
return await getUserPageProps(context);
};