* 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: benny@cal.com <sldisek783@gmail.com> * 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>
108 lines
3.1 KiB
TypeScript
108 lines
3.1 KiB
TypeScript
import process from "node:process";
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
import { symmetricDecrypt } from "@calcom/lib/crypto";
|
|
import { distributedTracing } from "@calcom/lib/tracing/factory";
|
|
import prisma from "@calcom/prisma";
|
|
import { confirmHandler } from "@calcom/trpc/server/routers/viewer/bookings/confirm.handler";
|
|
import { TRPCError } from "@trpc/server";
|
|
import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
|
|
import type { NextRequest } from "next/server";
|
|
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
|
|
enum DirectAction {
|
|
ACCEPT = "accept",
|
|
REJECT = "reject",
|
|
}
|
|
|
|
const querySchema = z.object({
|
|
action: z.nativeEnum(DirectAction),
|
|
token: z.string(),
|
|
reason: z.string().optional(),
|
|
});
|
|
|
|
const decryptedSchema = z.object({
|
|
bookingUid: z.string(),
|
|
userId: z.number().int(),
|
|
platformClientId: z.string().optional(),
|
|
platformRescheduleUrl: z.string().optional(),
|
|
platformCancelUrl: z.string().optional(),
|
|
platformBookingUrl: z.string().optional(),
|
|
});
|
|
|
|
async function handler(request: NextRequest) {
|
|
const searchParams = request.nextUrl.searchParams;
|
|
|
|
const { action, token, reason } = querySchema.parse(Object.fromEntries(searchParams.entries()));
|
|
|
|
const decryptedData = JSON.parse(
|
|
symmetricDecrypt(decodeURIComponent(token), process.env.CALENDSO_ENCRYPTION_KEY || "")
|
|
);
|
|
|
|
const {
|
|
bookingUid,
|
|
userId,
|
|
platformClientId,
|
|
platformRescheduleUrl,
|
|
platformCancelUrl,
|
|
platformBookingUrl,
|
|
} = decryptedSchema.parse(decryptedData);
|
|
|
|
const booking = await prisma.booking.findUniqueOrThrow({
|
|
where: { uid: bookingUid },
|
|
});
|
|
|
|
const user = await prisma.user.findUniqueOrThrow({
|
|
where: { id: userId },
|
|
select: {
|
|
id: true,
|
|
uuid: true,
|
|
email: true,
|
|
username: true,
|
|
role: true,
|
|
destinationCalendar: true,
|
|
},
|
|
});
|
|
|
|
try {
|
|
await confirmHandler({
|
|
ctx: {
|
|
user: {
|
|
id: user.id,
|
|
uuid: user.uuid,
|
|
email: user.email,
|
|
username: user.username ?? "",
|
|
role: user.role,
|
|
destinationCalendar: user.destinationCalendar ?? null,
|
|
},
|
|
traceContext: distributedTracing.createTrace("confirm_booking_magic_link"),
|
|
},
|
|
input: {
|
|
bookingId: booking.id,
|
|
recurringEventId: booking.recurringEventId || undefined,
|
|
confirmed: action === DirectAction.ACCEPT,
|
|
reason,
|
|
emailsEnabled: true,
|
|
platformClientParams: platformClientId
|
|
? {
|
|
platformClientId,
|
|
platformRescheduleUrl,
|
|
platformCancelUrl,
|
|
platformBookingUrl,
|
|
}
|
|
: undefined,
|
|
},
|
|
});
|
|
} catch (e) {
|
|
let message = "Error confirming booking";
|
|
if (e instanceof TRPCError) message = (e as TRPCError).message;
|
|
return NextResponse.redirect(
|
|
new URL(`/booking/${bookingUid}?error=${encodeURIComponent(message)}`, WEBAPP_URL)
|
|
);
|
|
}
|
|
|
|
return NextResponse.redirect(new URL(`/booking/${bookingUid}`, WEBAPP_URL));
|
|
}
|
|
|
|
export const GET = defaultResponderForAppDir(handler);
|