From 3dd3372c35cb1e79fe174e8531443ccc03391fd0 Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Mon, 16 Jun 2025 15:34:02 +0300 Subject: [PATCH] fix: getBookings for team admins within orgs (#21833) * fix: getBookings for team admins within orgs * fixup! fix: getBookings for team admins within orgs * chore: update getUserIdsAndEmailsWhereUserIsAdminOrOwner and remove unused orgId --------- Co-authored-by: Anik Dhabal Babu <81948346+anikdhabal@users.noreply.github.com> --- apps/api/v2/package.json | 2 +- .../2024-08-13/services/cal-video.service.ts | 2 +- apps/api/v2/swagger/documentation.json | 13 ++++++-- apps/api/v2/tsconfig.json | 3 +- docs/api-reference/v2/openapi.json | 12 ++++++- packages/platform/libraries/conferencing.ts | 5 +++ packages/platform/libraries/index.ts | 6 ---- packages/platform/libraries/package.json | 8 +++++ packages/platform/libraries/vite.config.js | 1 + .../routers/viewer/bookings/get.handler.ts | 31 +++++++------------ 10 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 packages/platform/libraries/conferencing.ts diff --git a/apps/api/v2/package.json b/apps/api/v2/package.json index a9a14c26a8..706cd1cb78 100644 --- a/apps/api/v2/package.json +++ b/apps/api/v2/package.json @@ -37,7 +37,7 @@ "@axiomhq/winston": "^1.2.0", "@calcom/platform-constants": "*", "@calcom/platform-enums": "*", - "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.222", + "@calcom/platform-libraries": "npm:@calcom/platform-libraries@0.0.223", "@calcom/platform-libraries-0.0.2": "npm:@calcom/platform-libraries@0.0.2", "@calcom/platform-types": "*", "@calcom/platform-utils": "*", diff --git a/apps/api/v2/src/ee/bookings/2024-08-13/services/cal-video.service.ts b/apps/api/v2/src/ee/bookings/2024-08-13/services/cal-video.service.ts index 6a7db7f7f0..531113296d 100644 --- a/apps/api/v2/src/ee/bookings/2024-08-13/services/cal-video.service.ts +++ b/apps/api/v2/src/ee/bookings/2024-08-13/services/cal-video.service.ts @@ -6,7 +6,7 @@ import { getRecordingsOfCalVideoByRoomName, getAllTranscriptsAccessLinkFromRoomName, getDownloadLinkOfCalVideoByRecordingId, -} from "@calcom/platform-libraries"; +} from "@calcom/platform-libraries/conferencing"; @Injectable() export class CalVideoService { diff --git a/apps/api/v2/swagger/documentation.json b/apps/api/v2/swagger/documentation.json index 20906bda66..44115dfa19 100644 --- a/apps/api/v2/swagger/documentation.json +++ b/apps/api/v2/swagger/documentation.json @@ -10695,6 +10695,16 @@ "type": "string" } }, + { + "name": "bookingUidToReschedule", + "required": false, + "in": "query", + "description": "The unique identifier of the booking being rescheduled. When provided will ensure that the original booking time appears within the returned available slots when rescheduling.", + "example": "abc123def456", + "schema": { + "type": "string" + } + }, { "name": "routingFormId", "required": true, @@ -25447,8 +25457,7 @@ "startTs", "status", "duration", - "shareToken", - "downloadLink" + "shareToken" ] }, "GetBookingRecordingsOutput": { diff --git a/apps/api/v2/tsconfig.json b/apps/api/v2/tsconfig.json index 947a676283..2c8cc688d5 100644 --- a/apps/api/v2/tsconfig.json +++ b/apps/api/v2/tsconfig.json @@ -24,7 +24,8 @@ "@calcom/platform-libraries/emails": ["../../../packages/platform/libraries/emails.ts"], "@calcom/platform-libraries/schedules": ["../../../packages/platform/libraries/schedules.ts"], "@calcom/platform-libraries/app-store": ["../../../packages/platform/libraries/app-store.ts"], - "@calcom/platform-libraries/workflows": ["../../../packages/platform/libraries/workflows.ts"] + "@calcom/platform-libraries/workflows": ["../../../packages/platform/libraries/workflows.ts"], + "@calcom/platform-libraries/conferencing": ["../../../packages/platform/libraries/conferencing.ts"] }, "incremental": true, "skipLibCheck": true, diff --git a/docs/api-reference/v2/openapi.json b/docs/api-reference/v2/openapi.json index e5b519381f..c638b9dcc4 100644 --- a/docs/api-reference/v2/openapi.json +++ b/docs/api-reference/v2/openapi.json @@ -10205,6 +10205,16 @@ "type": "string" } }, + { + "name": "bookingUidToReschedule", + "required": false, + "in": "query", + "description": "The unique identifier of the booking being rescheduled. When provided will ensure that the original booking time appears within the returned available slots when rescheduling.", + "example": "abc123def456", + "schema": { + "type": "string" + } + }, { "name": "routingFormId", "required": true, @@ -23342,7 +23352,7 @@ "example": "Error message" } }, - "required": ["id", "roomName", "startTs", "status", "duration", "shareToken", "downloadLink"] + "required": ["id", "roomName", "startTs", "status", "duration", "shareToken"] }, "GetBookingRecordingsOutput": { "type": "object", diff --git a/packages/platform/libraries/conferencing.ts b/packages/platform/libraries/conferencing.ts new file mode 100644 index 0000000000..b5bed7b4e8 --- /dev/null +++ b/packages/platform/libraries/conferencing.ts @@ -0,0 +1,5 @@ +export { + getRecordingsOfCalVideoByRoomName, + getDownloadLinkOfCalVideoByRecordingId, + getAllTranscriptsAccessLinkFromRoomName, +} from "@calcom/lib/videoClient"; diff --git a/packages/platform/libraries/index.ts b/packages/platform/libraries/index.ts index 0846714ec7..6c42c1d80d 100644 --- a/packages/platform/libraries/index.ts +++ b/packages/platform/libraries/index.ts @@ -74,12 +74,6 @@ export { getTranslation }; export { roundRobinReassignment } from "@calcom/features/ee/round-robin/roundRobinReassignment"; export { roundRobinManualReassignment } from "@calcom/features/ee/round-robin/roundRobinManualReassignment"; -export { - getRecordingsOfCalVideoByRoomName, - getDownloadLinkOfCalVideoByRecordingId, - getAllTranscriptsAccessLinkFromRoomName, -} from "@calcom/lib/videoClient"; - export { ErrorCode } from "@calcom/lib/errorCodes"; export { validateCustomEventName } from "@calcom/lib/event"; diff --git a/packages/platform/libraries/package.json b/packages/platform/libraries/package.json index 426f6083bf..a0db3653d7 100644 --- a/packages/platform/libraries/package.json +++ b/packages/platform/libraries/package.json @@ -63,6 +63,11 @@ "import": "./dist/slots.js", "require": "./dist/slots.cjs", "types": "./dist/slots.d.ts" + }, + "./conferencing": { + "import": "./dist/conferencing.js", + "require": "./dist/conferencing.cjs", + "types": "./dist/conferencing.d.ts" } }, "typesVersions": { @@ -84,6 +89,9 @@ ], "workflows": [ "dist/workflows.d.ts" + ], + "conferencing": [ + "dist/conferencing.d.ts" ] } } diff --git a/packages/platform/libraries/vite.config.js b/packages/platform/libraries/vite.config.js index 743f8b4128..96ceb96242 100644 --- a/packages/platform/libraries/vite.config.js +++ b/packages/platform/libraries/vite.config.js @@ -24,6 +24,7 @@ export default defineConfig({ "app-store": resolve(__dirname, "./app-store.ts"), workflows: resolve(__dirname, "./workflows.ts"), slots: resolve(__dirname, "./slots.ts"), + conferencing: resolve(__dirname, "./conferencing.ts"), }, name: "calcom-lib", fileName: "calcom-lib", diff --git a/packages/trpc/server/routers/viewer/bookings/get.handler.ts b/packages/trpc/server/routers/viewer/bookings/get.handler.ts index c2d79dcd72..a46eb944b2 100644 --- a/packages/trpc/server/routers/viewer/bookings/get.handler.ts +++ b/packages/trpc/server/routers/viewer/bookings/get.handler.ts @@ -123,7 +123,7 @@ export async function getBookings({ getAttendeeEmailsFromUserIdsFilter(prisma, user.email, filters?.userIds), getEventTypeIdsFromEventTypeIdsFilter(prisma, filters?.eventTypeIds), getEventTypeIdsWhereUserIsAdminOrOwner(prisma, membershipConditionWhereUserIsAdminOwner), - getUserIdsAndEmailsWhereUserIsAdminOrOwner(prisma, membershipConditionWhereUserIsAdminOwner, user.orgId), + getUserIdsAndEmailsWhereUserIsAdminOrOwner(prisma, membershipConditionWhereUserIsAdminOwner), ]); const bookingQueries: { query: BookingsUnionQuery; tables: (keyof DB)[] }[] = []; @@ -829,34 +829,22 @@ async function getEventTypeIdsWhereUserIsAdminOrOwner( } /** - * Gets [IDs, Emails] of members where the auth user is admin/owner. - * Scope depends on `orgId`: - * - If set (number): Fetches members of that specific organization (`isOrganization: true`). - * - If unset (null/undefined): Fetches members of all teams (`isOrganization: false`) - * where the auth user meets the `membershipCondition`. - * + * Gets [IDs, Emails] of members where the auth user is team/org admin/owner. * @param prisma The Prisma client. - * @param membershipCondition Filter defining the auth user's required role (e.g., OWNER/ADMIN) - * to identify the target orgs/teams. - * @param orgId Optional ID to target a specific org; absence targets teams. + * @param membershipCondition Filter containing the team/org ids where user is ADMIN/OWNER * @returns {Promise<[number[], string[]]>} [UserIDs, UserEmails] for members in the determined scope. */ async function getUserIdsAndEmailsWhereUserIsAdminOrOwner( prisma: PrismaClient, - membershipCondition: PrismaClientType.MembershipListRelationFilter, - orgId?: number | null + membershipCondition: PrismaClientType.MembershipListRelationFilter ): Promise<[number[], string[]]> { const users = await prisma.user.findMany({ where: { teams: { some: { - team: orgId - ? { - isOrganization: true, - members: membershipCondition, - id: orgId, - } - : { isOrganization: false, members: membershipCondition, parentId: null }, + team: { + members: membershipCondition, + }, }, }, }, @@ -865,7 +853,10 @@ async function getUserIdsAndEmailsWhereUserIsAdminOrOwner( email: true, }, }); - return [users.map((user) => user.id), users.map((user) => user.email)]; + const userIds = Array.from(new Set(users.map((user) => user.id))); + const userEmails = Array.from(new Set(users.map((user) => user.email))); + + return [userIds, userEmails]; } function addStatusesQueryFilters(query: BookingsUnionQuery, statuses: InputByStatus[]) {