From 295cf40c6ea310ce58ccb8ebf62e144bdb7958ac Mon Sep 17 00:00:00 2001 From: Vachmara <55046446+vachmara@users.noreply.github.com> Date: Sat, 29 Mar 2025 06:26:07 +0100 Subject: [PATCH] fix(intercom app): team / org url validation (#20431) --- .../app-store/intercom/lib/isValidCalURL.ts | 82 +------------------ 1 file changed, 2 insertions(+), 80 deletions(-) diff --git a/packages/app-store/intercom/lib/isValidCalURL.ts b/packages/app-store/intercom/lib/isValidCalURL.ts index b51ecbc664..9d961b91e5 100644 --- a/packages/app-store/intercom/lib/isValidCalURL.ts +++ b/packages/app-store/intercom/lib/isValidCalURL.ts @@ -1,5 +1,4 @@ import { CAL_URL } from "@calcom/lib/constants"; -import prisma from "@calcom/prisma"; import type { TextComponent } from "../lib"; @@ -27,91 +26,14 @@ export async function isValidCalURL(url: string) { error, }; - const urlWithoutCal = url.replace(regex, ""); + const response = await fetch(url); - const urlParts = urlWithoutCal.split("/"); - const usernameOrTeamSlug = urlParts[0]; - const eventTypeSlug = urlParts[1]; - - if (!usernameOrTeamSlug || !eventTypeSlug) + if (response.status !== 200) return { isValid: false, error, }; - // Find all potential users with the given username - const potentialUsers = await prisma.user.findMany({ - where: { - username: usernameOrTeamSlug, - }, - include: { - eventTypes: { - where: { - slug: eventTypeSlug, - hidden: false, - }, - }, - }, - }); - - // Find all potential teams with the given slug - const potentialTeams = await prisma.team.findMany({ - where: { - slug: usernameOrTeamSlug, - }, - include: { - eventTypes: { - where: { - slug: eventTypeSlug, - hidden: false, - }, - }, - }, - }); - - // Check if any user has the matching eventTypeSlug - const matchingUser = potentialUsers.find((user) => user.eventTypes.length > 0); - - // Check if any team has the matching eventTypeSlug - const matchingTeam = potentialTeams.find((team) => team.eventTypes.length > 0); - - if (!matchingUser && !matchingTeam) - return { - isValid: false, - error: { - ...error, - text: `${usernameOrTeamSlug} team or user is not valid.`, - }, - }; - - const userOrTeam = matchingUser || matchingTeam; - - if (!userOrTeam) - return { - isValid: false, - error, - }; - - // Retrieve the correct user or team - const userOrTeamId = userOrTeam.id; - - const eventType = await prisma.eventType.findFirst({ - where: { - userId: userOrTeamId, - slug: eventTypeSlug, - hidden: false, - }, - }); - - if (!eventType) - return { - isValid: false, - error: { - ...error, - text: `The event ${eventTypeSlug} doesn't exist.`, - }, - }; - return { isValid: true, };