mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +00:00
* 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>
139 lines
4.2 KiB
TypeScript
139 lines
4.2 KiB
TypeScript
import { WEBAPP_URL } from "@calcom/lib/constants";
|
|
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 { parseRequestData } from "app/api/parseRequestData";
|
|
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(),
|
|
bookingUid: z.string(),
|
|
userId: z.string(),
|
|
});
|
|
|
|
async function getHandler(request: NextRequest) {
|
|
const queryParams = Object.fromEntries(request.nextUrl.searchParams.entries());
|
|
|
|
try {
|
|
const { action, token, bookingUid, userId } = querySchema.parse(queryParams);
|
|
|
|
if (action === DirectAction.REJECT) {
|
|
// Rejections should use POST method
|
|
return NextResponse.redirect(
|
|
new URL(
|
|
`/booking/${bookingUid}?error=${encodeURIComponent("Rejection requires POST method")}`,
|
|
WEBAPP_URL
|
|
)
|
|
);
|
|
}
|
|
|
|
return await handleBookingAction(action, token, bookingUid, userId, request, undefined);
|
|
} catch {
|
|
const bookingUid = queryParams.bookingUid || "";
|
|
return NextResponse.redirect(
|
|
new URL(`/booking/${bookingUid}?error=${encodeURIComponent("Error confirming booking")}`, WEBAPP_URL)
|
|
);
|
|
}
|
|
}
|
|
|
|
async function postHandler(request: NextRequest) {
|
|
const queryParams = Object.fromEntries(request.nextUrl.searchParams.entries());
|
|
|
|
try {
|
|
const { action, token, bookingUid, userId } = querySchema.parse(queryParams);
|
|
const body = await parseRequestData(request).catch(() => ({}));
|
|
const { reason } = z.object({ reason: z.string().optional() }).parse(body || {});
|
|
|
|
return await handleBookingAction(action, token, bookingUid, userId, request, reason);
|
|
} catch {
|
|
const bookingUid = queryParams.bookingUid || "";
|
|
return NextResponse.redirect(
|
|
new URL(`/booking/${bookingUid}?error=${encodeURIComponent("Error confirming booking")}`, WEBAPP_URL),
|
|
{ status: 303 }
|
|
);
|
|
}
|
|
}
|
|
|
|
async function handleBookingAction(
|
|
action: DirectAction,
|
|
token: string,
|
|
bookingUid: string,
|
|
userId: string,
|
|
_request: NextRequest,
|
|
reason?: string
|
|
) {
|
|
const booking = await prisma.booking.findUnique({
|
|
where: { oneTimePassword: token },
|
|
});
|
|
|
|
if (!booking) {
|
|
return NextResponse.redirect(
|
|
new URL(`/booking/${bookingUid}?error=${encodeURIComponent("Error confirming booking")}`, WEBAPP_URL),
|
|
{ status: 303 }
|
|
);
|
|
}
|
|
|
|
const user = await prisma.user.findUniqueOrThrow({
|
|
where: { id: Number(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_verify_token"),
|
|
},
|
|
input: {
|
|
bookingId: booking.id,
|
|
recurringEventId: booking.recurringEventId || undefined,
|
|
confirmed: action === DirectAction.ACCEPT,
|
|
/** Ignored reason input unless we're rejecting */
|
|
reason: action === DirectAction.REJECT ? reason : undefined,
|
|
emailsEnabled: true,
|
|
},
|
|
});
|
|
} catch (e) {
|
|
let message = "Error confirming booking";
|
|
if (e instanceof TRPCError) message = (e as TRPCError).message;
|
|
return NextResponse.redirect(
|
|
new URL(`/booking/${booking.uid}?error=${encodeURIComponent(message)}`, WEBAPP_URL),
|
|
{ status: 303 }
|
|
);
|
|
}
|
|
|
|
await prisma.booking.update({
|
|
where: { id: booking.id },
|
|
data: { oneTimePassword: null },
|
|
});
|
|
|
|
return NextResponse.redirect(new URL(`/booking/${booking.uid}`, WEBAPP_URL), { status: 303 });
|
|
}
|
|
|
|
export const GET = defaultResponderForAppDir(getHandler);
|
|
export const POST = defaultResponderForAppDir(postHandler);
|