Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure event type duplication respects private link setting #13438

Merged
merged 10 commits into from
Feb 7, 2024
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Prisma } from "@prisma/client";
import short from "short-uuid";
import { v5 as uuidv5 } from "uuid";

import { prisma } from "@calcom/prisma";

Expand All @@ -15,6 +17,13 @@ type DuplicateOptions = {
input: TDuplicateInputSchema;
};

export const generateHashedLink = (id: number) => {
SomayChauhan marked this conversation as resolved.
Show resolved Hide resolved
const translator = short();
const seed = `${id}:${new Date().getTime()}`;
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
return uid;
};

export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
try {
const {
Expand All @@ -35,6 +44,7 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
team: true,
workflows: true,
webhooks: true,
hashedLink: true,
destinationCalendar: true,
},
});
Expand Down Expand Up @@ -68,6 +78,7 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
durationLimits,
metadata,
workflows,
hashedLink,
destinationCalendar,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
id: _id,
Expand Down Expand Up @@ -114,6 +125,17 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
});
}

if (hashedLink) {
await prisma.hashedLink.create({
data: {
link: generateHashedLink(users[0].id ?? newEventType.teamId),
eventType: {
connect: { id: newEventType.id },
},
},
});
}

if (workflows.length > 0) {
const relationCreateData = workflows.map((workflow) => {
return { eventTypeId: newEventType.id, workflowId: workflow.workflowId };
Expand Down
Loading