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 <[email protected]>
This commit is contained in:
1 parent
d2b4760e3a
commit
a0451e34c1
4 files changed
+25
-18
No files matched your search
@@ -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