Scheduling infrastructure for absolutely everyone.
fix: prevent bulk update of locked locations in child managed event types (#24978)
Joe Au-Yeung717a26f22323
diff --git a/apps/web/lib/apps/installation/[[...step]]/getServerSideProps.ts b/apps/web/lib/apps/installation/[[...step]]/getServerSideProps.tsindex aff52219662..bc92a0a7817 100644--- a/apps/web/lib/apps/installation/[[...step]]/getServerSideProps.ts+++ b/apps/web/lib/apps/installation/[[...step]]/getServerSideProps.ts@@ -1,6 +1,7 @@import type { GetServerSidePropsContext } from "next";import { z } from "zod";+import { filterEventTypesWhereLocationUpdateIsAllowed } from "@calcom/app-store/_utils/getBulkEventTypes";import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";import type { LocationObject } from "@calcom/app-store/locations";import { isConferencing as isConferencingApp } from "@calcom/app-store/utils";@@ -73,7 +74,15 @@ const getAppBySlug = async (appSlug: string) => {return app;};-const getEventTypes = async (userId: number, teamIds?: number[]) => {+const getEventTypes = async ({+ userId,+ teamIds,+ isConferencing = false,+}: {+ userId: number;+ teamIds?: number[];+ isConferencing?: boolean;+}) => {const eventTypeSelect = {id: true,description: true,@@ -96,6 +105,7 @@ const getEventTypes = async (userId: number, teamIds?: number[]) => {destinationCalendar: true,bookingFields: true,calVideoSettings: true,+ parentId: true,} satisfies Prisma.EventTypeSelect;let eventTypeGroups: TEventTypeGroup[] | null = [];@@ -119,22 +129,28 @@ const getEventTypes = async (userId: number, teamIds?: number[]) => {},},});- eventTypeGroups = teams.map((team) => ({- teamId: team.id,- slug: team.slug,- name: team.name,- isOrganisation: team.isOrganization,- image: getPlaceholderAvatar(team.logoUrl, team.name),- eventTypes: team.eventTypes- .map((item) => ({- ...item,- URL: `${CAL_URL}/${item.team ? `team/${item.team.slug}` : item?.users?.[0]?.username}/${item.slug}`,- selected: false,- locations: item.locations as unknown as LocationObject[],- bookingFields: eventTypeBookingFields.parse(item.bookingFields || []),- }))- .sort((eventTypeA, eventTypeB) => eventTypeB.position - eventTypeA.position),- }));+ eventTypeGroups = teams.map((team) => {+ const filteredEventTypes = isConferencing+ ? filterEventTypesWhereLocationUpdateIsAllowed(team.eventTypes)+ : team.eventTypes;++ return {+ teamId: team.id,+ slug: team.slug,+ name: team.name,+ isOrganisation: team.isOrganization,+ image: getPlaceholderAvatar(team.logoUrl, team.name),+ eventTypes: filteredEventTypes+ .map((item) => ({+ ...item,+ URL: `${CAL_URL}/${item.team ? `team/${item.team.slug}` : item?.users?.[0]?.username}/${item.slug}`,+ selected: false,+ locations: item.locations as unknown as LocationObject[],+ bookingFields: eventTypeBookingFields.parse(item.bookingFields || []),+ }))+ .sort((eventTypeA, eventTypeB) => eventTypeB.position - eventTypeA.position),+ };+ });} else {const user = await prisma.user.findUnique({where: {@@ -155,12 +171,16 @@ const getEventTypes = async (userId: number, teamIds?: number[]) => {});if (user) {+ const filteredEventTypes = isConferencing+ ? filterEventTypesWhereLocationUpdateIsAllowed(user.eventTypes)+ : user.eventTypes;+eventTypeGroups.push({userId: user.id,slug: user.username,name: user.name,image: getPlaceholderAvatar(user.avatarUrl, user.name),- eventTypes: user.eventTypes+ eventTypes: filteredEventTypes.map((item) => ({...item,URL: `${CAL_URL}/${item.team ? `team/${item.team.slug}` : item?.users?.[0]?.username}/${@@ -208,7 +228,7 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>const _ = stepsEnum.parse(parsedStepParam);const session = await getServerSession({ req });if (!session?.user?.id) return { redirect: { permanent: false, destination: "/auth/login" } };- const locale = await getLocale(context.req);+ const _locale = await getLocale(context.req);const app = await getAppBySlug(parsedAppSlug);if (!app) return { redirect: { permanent: false, destination: "/apps" } };const appMetadata = appStoreMetadata[app.dirName as keyof typeof appStoreMetadata];@@ -246,11 +266,11 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) =>}if (isOrg) {const teamIds = userTeams.map((item) => item.id);- eventTypeGroups = await getEventTypes(user.id, teamIds);+ eventTypeGroups = await getEventTypes({ userId: user.id, teamIds, isConferencing });} else if (parsedTeamIdParam) {- eventTypeGroups = await getEventTypes(user.id, [parsedTeamIdParam]);+ eventTypeGroups = await getEventTypes({ userId: user.id, teamIds: [parsedTeamIdParam], isConferencing });} else {- eventTypeGroups = await getEventTypes(user.id);+ eventTypeGroups = await getEventTypes({ userId: user.id, isConferencing });}if (isConferencing && eventTypeGroups) {const destinationCalendar = await prisma.destinationCalendar.findFirst({diff --git a/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.test.ts b/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.test.tsnew file mode 100644index 00000000000..c9a72091791--- /dev/null+++ b/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.test.ts@@ -0,0 +1,348 @@+import { describe, expect, it, beforeEach, vi } from "vitest";++import type { PrismaClient } from "@calcom/prisma";++import { bulkUpdateEventsToDefaultLocation } from "./bulkUpdateEventsToDefaultLocation";++vi.mock("../utils", () => ({+ getAppFromSlug: vi.fn((slug: string) => {+ if (slug === "google-meet") {+ return {+ slug: "google-meet",+ appData: {+ location: {+ type: "integrations:google:meet",+ },+ },+ };+ }+ if (slug === "zoom") {+ return {+ slug: "zoom",+ appData: {+ location: {+ type: "integrations:zoom",+ },+ },+ };+ }+ return null;+ }),+}));++type MockPrisma = {+ credential: {+ findFirst: ReturnType<typeof vi.fn>;+ };+ eventType: {+ findMany: ReturnType<typeof vi.fn>;+ updateMany: ReturnType<typeof vi.fn>;+ };+};++const createMockPrisma = (): MockPrisma => ({+ credential: {+ findFirst: vi.fn(),+ },+ eventType: {+ findMany: vi.fn(),+ updateMany: vi.fn(),+ },+});++describe("bulkUpdateEventsToDefaultLocation", () => {+ let mockPrisma: MockPrisma;++ beforeEach(() => {+ mockPrisma = createMockPrisma();+ vi.clearAllMocks();+ });++ it("should throw error when default conferencing app is not set", async () => {+ const user = {+ id: 1,+ metadata: {},+ };++ await expect(+ bulkUpdateEventsToDefaultLocation({+ eventTypeIds: [1, 2],+ user,+ prisma: mockPrisma as unknown as PrismaClient,+ })+ ).rejects.toThrow("Default conferencing app not set");+ });++ it("should throw error when default conferencing app doesn't exist", async () => {+ const user = {+ id: 1,+ metadata: {+ defaultConferencingApp: {+ appSlug: "non-existent-app",+ appLink: "https://example.com",+ },+ },+ };++ await expect(+ bulkUpdateEventsToDefaultLocation({+ eventTypeIds: [1, 2],+ user,+ prisma: mockPrisma as unknown as PrismaClient,+ })+ ).rejects.toThrow("Default conferencing app 'non-existent-app' doesnt exist.");+ });++ it("should update event types that are not child managed events", async () => {+ const user = {+ id: 1,+ metadata: {+ defaultConferencingApp: {+ appSlug: "google-meet",+ appLink: "https://meet.google.com",+ },+ },+ };++ const credential = { id: 100 };+ const eventTypes = [+ { id: 1, parentId: null, metadata: {} },+ { id: 2, parentId: null, metadata: {} },+ ];++ mockPrisma.credential.findFirst.mockResolvedValue(credential);+ mockPrisma.eventType.findMany.mockResolvedValue(eventTypes);+ mockPrisma.eventType.updateMany.mockResolvedValue({ count: 2 });++ const result = await bulkUpdateEventsToDefaultLocation({+ eventTypeIds: [1, 2],+ user,+ prisma: mockPrisma as unknown as PrismaClient,+ });++ expect(result.count).toBe(2);+ expect(mockPrisma.eventType.updateMany).toHaveBeenCalledWith({+ where: {+ id: {+ in: [1, 2],+ },+ userId: 1,+ },+ data: {+ locations: [+ {+ type: "integrations:google:meet",+ link: "https://meet.google.com",+ credentialId: 100,+ },+ ],+ },+ });+ });++ it("should filter out child managed event types with locked locations", async () => {+ const user = {+ id: 1,+ metadata: {+ defaultConferencingApp: {+ appSlug: "zoom",+ appLink: "https://zoom.us",+ },+ },+ };++ const credential = { id: 200 };+ const eventTypes = [+ { id: 1, parentId: null, metadata: {} },+ {+ id: 2,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ },+ },+ },+ },+ {+ id: 3,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: true, // unlocked+ },+ },+ },+ },+ ];++ mockPrisma.credential.findFirst.mockResolvedValue(credential);+ mockPrisma.eventType.findMany.mockResolvedValue(eventTypes);+ mockPrisma.eventType.updateMany.mockResolvedValue({ count: 2 });++ const result = await bulkUpdateEventsToDefaultLocation({+ eventTypeIds: [1, 2, 3],+ user,+ prisma: mockPrisma as unknown as PrismaClient,+ });++ expect(result.count).toBe(2);+ expect(mockPrisma.eventType.updateMany).toHaveBeenCalledWith({+ where: {+ id: {+ in: [1, 3],+ },+ userId: 1,+ },+ data: {+ locations: [+ {+ type: "integrations:zoom",+ link: "https://zoom.us",+ credentialId: 200,+ },+ ],+ },+ });+ });++ it("should return count 0 when all event types have locked locations", async () => {+ const user = {+ id: 1,+ metadata: {+ defaultConferencingApp: {+ appSlug: "google-meet",+ appLink: "https://meet.google.com",+ },+ },+ };++ const credential = { id: 300 };+ const eventTypes = [+ {+ id: 1,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ },+ },+ },+ },+ {+ id: 2,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: false, // explicitly locked+ },+ },+ },+ },+ ];++ mockPrisma.credential.findFirst.mockResolvedValue(credential);+ mockPrisma.eventType.findMany.mockResolvedValue(eventTypes);++ const result = await bulkUpdateEventsToDefaultLocation({+ eventTypeIds: [1, 2],+ user,+ prisma: mockPrisma as unknown as PrismaClient,+ });++ expect(result.count).toBe(0);+ expect(mockPrisma.eventType.updateMany).not.toHaveBeenCalled();+ });++ it("should work without credential when credential is not found", async () => {+ const user = {+ id: 1,+ metadata: {+ defaultConferencingApp: {+ appSlug: "google-meet",+ appLink: "https://meet.google.com",+ },+ },+ };++ const eventTypes = [{ id: 1, parentId: null, metadata: {} }];++ mockPrisma.credential.findFirst.mockResolvedValue(null);+ mockPrisma.eventType.findMany.mockResolvedValue(eventTypes);+ mockPrisma.eventType.updateMany.mockResolvedValue({ count: 1 });++ const result = await bulkUpdateEventsToDefaultLocation({+ eventTypeIds: [1],+ user,+ prisma: mockPrisma as unknown as PrismaClient,+ });++ expect(result.count).toBe(1);+ expect(mockPrisma.eventType.updateMany).toHaveBeenCalledWith({+ where: {+ id: {+ in: [1],+ },+ userId: 1,+ },+ data: {+ locations: [+ {+ type: "integrations:google:meet",+ link: "https://meet.google.com",+ credentialId: undefined,+ },+ ],+ },+ });+ });++ it("should only query event types belonging to the user", async () => {+ const user = {+ id: 5,+ metadata: {+ defaultConferencingApp: {+ appSlug: "zoom",+ appLink: "https://zoom.us",+ },+ },+ };++ const credential = { id: 400 };+ const eventTypes = [{ id: 10, parentId: null, metadata: {} }];++ mockPrisma.credential.findFirst.mockResolvedValue(credential);+ mockPrisma.eventType.findMany.mockResolvedValue(eventTypes);+ mockPrisma.eventType.updateMany.mockResolvedValue({ count: 1 });++ await bulkUpdateEventsToDefaultLocation({+ eventTypeIds: [10, 11, 12],+ user,+ prisma: mockPrisma as unknown as PrismaClient,+ });++ expect(mockPrisma.eventType.findMany).toHaveBeenCalledWith({+ where: {+ id: {+ in: [10, 11, 12],+ },+ userId: 5,+ },+ select: {+ id: true,+ metadata: true,+ parentId: true,+ },+ });++ expect(mockPrisma.eventType.updateMany).toHaveBeenCalledWith(+ expect.objectContaining({+ where: expect.objectContaining({+ userId: 5,+ }),+ })+ );+ });+});diff --git a/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.ts b/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.tsindex 1dd0bc3788c..f676e8f1fae 100644--- a/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.ts+++ b/packages/app-store/_utils/bulkUpdateEventsToDefaultLocation.ts@@ -4,6 +4,9 @@ import { userMetadata as userMetadataSchema } from "@calcom/prisma/zod-utils";import type { LocationObject } from "../locations";import { getAppFromSlug } from "../utils";+import { filterEventTypesWhereLocationUpdateIsAllowed } from "./getBulkEventTypes";++type PrismaLike = Pick<PrismaClient, "credential" | "eventType">;export const bulkUpdateEventsToDefaultLocation = async ({eventTypeIds,@@ -12,7 +15,7 @@ export const bulkUpdateEventsToDefaultLocation = async ({}: {eventTypeIds: number[];user: Pick<User, "id" | "metadata">;- prisma: PrismaClient;+ prisma: PrismaLike;}) => {const defaultApp = userMetadataSchema.parse(user.metadata)?.defaultConferencingApp;@@ -36,13 +39,35 @@ export const bulkUpdateEventsToDefaultLocation = async ({},});- return await prisma.eventType.updateMany({+ const eventTypesToUpdate = await prisma.eventType.findMany({where: {id: {in: eventTypeIds,},userId: user.id,},+ select: {+ id: true,+ metadata: true,+ parentId: true,+ },+ });++ const validEventTypeIds = filterEventTypesWhereLocationUpdateIsAllowed(eventTypesToUpdate).map(+ (eventType) => eventType.id+ );++ if (validEventTypeIds.length === 0) {+ return { count: 0 };+ }++ return await prisma.eventType.updateMany({+ where: {+ id: {+ in: validEventTypeIds,+ },+ userId: user.id,+ },data: {locations: [{ type: appType, link: defaultApp.appLink, credentialId: credential?.id },diff --git a/packages/app-store/_utils/getBulkEventTypes.test.ts b/packages/app-store/_utils/getBulkEventTypes.test.tsnew file mode 100644index 00000000000..c5af114a891--- /dev/null+++ b/packages/app-store/_utils/getBulkEventTypes.test.ts@@ -0,0 +1,364 @@+import { describe, expect, it, beforeEach, vi } from "vitest";++import type { Prisma } from "@calcom/prisma/client";++import { filterEventTypesWhereLocationUpdateIsAllowed, getBulkUserEventTypes } from "./getBulkEventTypes";++vi.mock("@calcom/prisma", () => ({+ prisma: {+ eventType: {+ findMany: vi.fn(),+ },+ },+}));++vi.mock("../utils", () => ({+ getAppFromLocationValue: vi.fn((locationType: string) => {+ if (locationType === "integrations:daily") {+ return { logo: "/daily-logo.svg" };+ }+ if (locationType === "integrations:google:meet") {+ return { logo: "/google-meet-logo.svg" };+ }+ return { logo: "/default-logo.svg" };+ }),+}));++import { prisma } from "@calcom/prisma";++describe("filterEventTypesWhereLocationUpdateIsAllowed", () => {+ it("should allow location updates for event types without a parent", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: null,+ metadata: {},+ },+ {+ id: 2,+ parentId: null,+ metadata: null,+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result).toHaveLength(2);+ expect(result).toEqual(eventTypes);+ });++ it("should allow location updates for child event types with unlocked locations", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: true,+ },+ },+ },+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result).toHaveLength(1);+ expect(result[0].id).toBe(1);+ });++ it("should block location updates for child event types with locked locations (locations field undefined)", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ },+ },+ },+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result).toHaveLength(0);+ });++ it("should block location updates for child event types with explicitly locked locations (locations: false)", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: false,+ },+ },+ },+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result).toHaveLength(0);+ });++ it("should allow location updates for child event types without managedEventConfig", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: 100,+ metadata: {+ },+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result).toHaveLength(1);+ expect(result[0].id).toBe(1);+ });++ it("should allow location updates for child event types with invalid metadata", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: 100,+ metadata: "invalid metadata",+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result).toHaveLength(1);+ expect(result[0].id).toBe(1);+ });++ it("should handle mixed scenarios correctly", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: null,+ metadata: {},+ },+ {+ id: 2,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: true,+ },+ },+ },+ },+ {+ id: 3,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ },+ },+ },+ },+ {+ id: 4,+ parentId: 100,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: false,+ },+ },+ },+ },+ {+ id: 5,+ parentId: 100,+ metadata: null,+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result).toHaveLength(3);+ expect(result.map((et) => et.id)).toEqual([1, 2, 5]);+ });++ it("should preserve all properties of filtered event types", () => {+ const eventTypes = [+ {+ id: 1,+ parentId: null,+ metadata: {},+ title: "Test Event",+ locations: [{ type: "integrations:daily" }],+ },+ ];++ const result = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);+ expect(result[0]).toEqual(eventTypes[0]);+ expect(result[0]).toHaveProperty("title");+ expect(result[0]).toHaveProperty("locations");+ });+});++describe("getBulkUserEventTypes", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ it("should return user event types with logos and filter out locked child events", async () => {+ const userId = 1;+ const mockEventTypes = [+ {+ id: 1,+ title: "Regular Event",+ locations: [{ type: "integrations:daily" }] as Prisma.JsonValue,+ metadata: {} as Prisma.JsonValue,+ parentId: null,+ },+ {+ id: 2,+ title: "Child Event - Unlocked",+ locations: [{ type: "integrations:google:meet" }] as Prisma.JsonValue,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: true,+ },+ },+ } as Prisma.JsonValue,+ parentId: 100,+ },+ {+ id: 3,+ title: "Child Event - Locked",+ locations: [{ type: "integrations:daily" }] as Prisma.JsonValue,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ },+ },+ } as Prisma.JsonValue,+ parentId: 100,+ },+ ];++ vi.mocked(prisma.eventType.findMany).mockResolvedValue(+ mockEventTypes as unknown as Awaited<ReturnType<typeof prisma.eventType.findMany>>+ );++ const result = await getBulkUserEventTypes(userId);++ expect(result.eventTypes).toHaveLength(2);+ expect(result.eventTypes[0].id).toBe(1);+ expect(result.eventTypes[0].title).toBe("Regular Event");+ expect(result.eventTypes[0].logo).toBe("/daily-logo.svg");+ expect(result.eventTypes[1].id).toBe(2);+ expect(result.eventTypes[1].title).toBe("Child Event - Unlocked");+ expect(result.eventTypes[1].logo).toBe("/google-meet-logo.svg");++ expect(prisma.eventType.findMany).toHaveBeenCalledWith({+ where: {+ userId: userId,+ teamId: null,+ },+ select: {+ id: true,+ title: true,+ locations: true,+ metadata: true,+ parentId: true,+ },+ });+ });++ it("should return all event types when none have locked locations", async () => {+ const userId = 2;+ const mockEventTypes = [+ {+ id: 10,+ title: "Event 1",+ locations: [{ type: "integrations:daily" }] as Prisma.JsonValue,+ metadata: {} as Prisma.JsonValue,+ parentId: null,+ },+ {+ id: 11,+ title: "Event 2",+ locations: [{ type: "integrations:daily" }] as Prisma.JsonValue,+ metadata: {} as Prisma.JsonValue,+ parentId: null,+ },+ ];++ vi.mocked(prisma.eventType.findMany).mockResolvedValue(+ mockEventTypes as unknown as Awaited<ReturnType<typeof prisma.eventType.findMany>>+ );++ const result = await getBulkUserEventTypes(userId);++ expect(result.eventTypes).toHaveLength(2);+ expect(result.eventTypes.map((et) => et.id)).toEqual([10, 11]);+ });++ it("should return empty array when all event types have locked locations", async () => {+ const userId = 3;+ const mockEventTypes = [+ {+ id: 20,+ title: "Locked Event 1",+ locations: [{ type: "integrations:daily" }] as Prisma.JsonValue,+ metadata: {+ managedEventConfig: {+ unlockedFields: {},+ },+ } as Prisma.JsonValue,+ parentId: 100,+ },+ {+ id: 21,+ title: "Locked Event 2",+ locations: [{ type: "integrations:daily" }] as Prisma.JsonValue,+ metadata: {+ managedEventConfig: {+ unlockedFields: {+ locations: false,+ },+ },+ } as Prisma.JsonValue,+ parentId: 100,+ },+ ];++ vi.mocked(prisma.eventType.findMany).mockResolvedValue(+ mockEventTypes as unknown as Awaited<ReturnType<typeof prisma.eventType.findMany>>+ );++ const result = await getBulkUserEventTypes(userId);++ expect(result.eventTypes).toHaveLength(0);+ });++ it("should handle event types with null locations gracefully", async () => {+ const userId = 4;+ const mockEventTypes = [+ {+ id: 30,+ title: "Event with null location",+ locations: null as unknown as Prisma.JsonValue,+ metadata: {} as Prisma.JsonValue,+ parentId: null,+ },+ ];++ vi.mocked(prisma.eventType.findMany).mockResolvedValue(+ mockEventTypes as unknown as Awaited<ReturnType<typeof prisma.eventType.findMany>>+ );++ const result = await getBulkUserEventTypes(userId);++ expect(result.eventTypes).toHaveLength(1);+ expect(result.eventTypes[0].id).toBe(30);+ expect(result.eventTypes[0].logo).toBe("/daily-logo.svg");+ });+});diff --git a/packages/app-store/_utils/getBulkEventTypes.ts b/packages/app-store/_utils/getBulkEventTypes.tsindex d2c573ae1d8..9876d33466b 100644--- a/packages/app-store/_utils/getBulkEventTypes.ts+++ b/packages/app-store/_utils/getBulkEventTypes.ts@@ -1,5 +1,8 @@import { prisma } from "@calcom/prisma";-import { eventTypeLocations as eventTypeLocationsSchema } from "@calcom/prisma/zod-utils";+import {+ eventTypeLocations as eventTypeLocationsSchema,+ eventTypeMetaDataSchemaWithoutApps,+} from "@calcom/prisma/zod-utils";import { getAppFromLocationValue } from "../utils";@@ -38,10 +41,19 @@ export const getBulkUserEventTypes = async (userId: number) => {id: true,title: true,locations: true,+ metadata: true,+ parentId: true,},});- return processEventTypes(eventTypes);+ const filteredEventTypes = filterEventTypesWhereLocationUpdateIsAllowed(eventTypes);++ return processEventTypes(+ filteredEventTypes.map((eventType) => {+ const { metadata: _metadata, ...rest } = eventType;+ return { ...rest };+ })+ );};export const getBulkTeamEventTypes = async (teamId: number) => {@@ -59,3 +71,24 @@ export const getBulkTeamEventTypes = async (teamId: number) => {return processEventTypes(eventTypes);};++export const filterEventTypesWhereLocationUpdateIsAllowed = <+ T extends { parentId: number | null; metadata: unknown }+>(+ eventTypes: T[]+): T[] => {+ const filteredEventTypes = eventTypes.filter((eventType) => {+ if (!eventType.parentId) {+ return true;+ }++ const metadata = eventTypeMetaDataSchemaWithoutApps.safeParse(eventType.metadata);+ if (!metadata.success || !metadata.data?.managedEventConfig) {+ return true;+ }++ const unlockedFields = metadata.data.managedEventConfig.unlockedFields;+ return unlockedFields?.locations === true;+ });+ return filteredEventTypes;+};diff --git a/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.integration-test.ts b/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.integration-test.tsindex dd5262f5a4f..eb0c59588d1 100644--- a/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.integration-test.ts+++ b/packages/trpc/server/routers/viewer/teams/inviteMember/inviteMember.handler.integration-test.ts@@ -4,6 +4,7 @@ import { prisma } from "@calcom/prisma";import type { Team, User, Membership, Profile } from "@calcom/prisma/client";import { MembershipRole } from "@calcom/prisma/enums";import type { TrpcSessionUser } from "@calcom/trpc/server/types";+import type { JsonValue } from "@calcom/types/Json";import inviteMemberHandler, { inviteMembersWithNoInviterPermissionCheck } from "./inviteMember.handler";@@ -65,7 +66,7 @@ async function createTestTeam(data: {slug: string;isOrganization?: boolean;parentId?: number;- metadata?: Record<string, unknown>;+ metadata?: JsonValue;organizationSettings?: {orgAutoAcceptEmail: string;isOrganizationVerified?: boolean;