fix: Ensure event type duplication respects private link setting (#13438)
* fix: Ensure event type duplication respects private link setting * chode refactor * Fix: Handler throwing error on creating duplicate of a collective event having private-link switched on. --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
co-authored by
Keith Williams
parent
d2b4760e3a
commit
a0451e34c1
@@ -3,8 +3,6 @@ import Link from "next/link";
|
||||
import type { EventTypeSetupProps, FormValues } from "pages/event-types/[type]";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Controller, useFormContext } from "react-hook-form";
|
||||
import short from "short-uuid";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
import type { z } from "zod";
|
||||
|
||||
import type { EventNameObjectType } from "@calcom/core/event";
|
||||
@@ -22,6 +20,7 @@ import { BookerLayoutSelector } from "@calcom/features/settings/BookerLayoutSele
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { APP_NAME, CAL_URL } from "@calcom/lib/constants";
|
||||
import { IS_VISUAL_REGRESSION_TESTING } from "@calcom/lib/constants";
|
||||
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import type { Prisma } from "@calcom/prisma/client";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
@@ -41,13 +40,6 @@ import RequiresConfirmationController from "./RequiresConfirmationController";
|
||||
|
||||
const CustomEventTypeModal = dynamic(() => import("@components/eventtype/CustomEventTypeModal"));
|
||||
|
||||
const generateHashedLink = (id: number) => {
|
||||
const translator = short();
|
||||
const seed = `${id}:${new Date().getTime()}`;
|
||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
||||
return uid;
|
||||
};
|
||||
|
||||
export const EventAdvancedTab = ({ eventType, team }: Pick<EventTypeSetupProps, "eventType" | "team">) => {
|
||||
const connectedCalendarsQuery = trpc.viewer.connectedCalendars.useQuery();
|
||||
const { data: user } = trpc.viewer.me.useQuery();
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
import type { Prisma } from "@prisma/client";
|
||||
import short from "short-uuid";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
import type { DeepMockProxy } from "vitest-mock-extended";
|
||||
|
||||
import { sendSlugReplacementEmail } from "@calcom/emails/email-manager";
|
||||
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
|
||||
import { getTranslation } from "@calcom/lib/server/i18n";
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
import { SchedulingType } from "@calcom/prisma/enums";
|
||||
import { _EventTypeModel } from "@calcom/prisma/zod";
|
||||
import { allManagedEventTypeProps, unlockedManagedEventTypeProps } from "@calcom/prisma/zod-utils";
|
||||
|
||||
const generateHashedLink = (id: number) => {
|
||||
const translator = short();
|
||||
const seed = `${id}:${new Date().getTime()}`;
|
||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
||||
return uid;
|
||||
};
|
||||
|
||||
interface handleChildrenEventTypesProps {
|
||||
eventTypeId: number;
|
||||
profileId: number | null;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import short from "short-uuid";
|
||||
import { v5 as uuidv5 } from "uuid";
|
||||
|
||||
export const generateHashedLink = (id: number) => {
|
||||
const translator = short();
|
||||
const seed = `${id}:${new Date().getTime()}`;
|
||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
||||
return uid;
|
||||
};
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import { generateHashedLink } from "@calcom/lib/generateHashedLink";
|
||||
import { EventTypeRepository } from "@calcom/lib/server/repository/eventType";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
|
||||
@@ -40,6 +41,7 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
|
||||
team: true,
|
||||
workflows: true,
|
||||
webhooks: true,
|
||||
hashedLink: true,
|
||||
destinationCalendar: true,
|
||||
},
|
||||
});
|
||||
@@ -73,6 +75,7 @@ export const duplicateHandler = async ({ ctx, input }: DuplicateOptions) => {
|
||||
durationLimits,
|
||||
metadata,
|
||||
workflows,
|
||||
hashedLink,
|
||||
destinationCalendar,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
id: _id,
|
||||
@@ -119,6 +122,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 };
|
||||
|
||||
Reference in New Issue
Block a user