-
Notifications
You must be signed in to change notification settings - Fork 12k
fix: Booker reschedule behaviour for org admin #26530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Ryukemeister
merged 9 commits into
main
from
fix-reschedule-behaviour-for-seated-bookings
Jan 13, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5678a3b
fix: reschedule behaviour for org admin
Ryukemeister 2f21b38
Merge branch 'main' into fix-reschedule-behaviour-for-seated-bookings
Ryukemeister d85c9a8
Merge branch 'main' into fix-reschedule-behaviour-for-seated-bookings
Ryukemeister 697de44
Merge branch 'main' into fix-reschedule-behaviour-for-seated-bookings
Ryukemeister dbd8281
fix: use pbac for permissions check
Ryukemeister 7ed6830
Merge branch 'main' into fix-reschedule-behaviour-for-seated-bookings
PeerRich a9e0a36
Merge branch 'main' into fix-reschedule-behaviour-for-seated-bookings
Ryukemeister a3155a8
Merge branch 'main' into fix-reschedule-behaviour-for-seated-bookings
ThyMinimalDev 19394e7
Merge branch 'main' into fix-reschedule-behaviour-for-seated-bookings
Ryukemeister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| import { bookingResponsesDbSchema } from "@calcom/features/bookings/lib/getBookingResponsesSchema"; | ||
| import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service"; | ||
| import slugify from "@calcom/lib/slugify"; | ||
| import type { PrismaClient } from "@calcom/prisma"; | ||
| import prisma from "@calcom/prisma"; | ||
| import type { Prisma } from "@calcom/prisma/client"; | ||
| import { MembershipRole } from "@calcom/prisma/enums"; | ||
|
|
||
| type BookingSelect = { | ||
| description: true; | ||
|
|
@@ -24,7 +26,8 @@ function getResponsesFromOldBooking( | |
| ) { | ||
| const customInputs = rawBooking.customInputs || {}; | ||
| const responses = Object.keys(customInputs).reduce((acc, label) => { | ||
| acc[slugify(label) as keyof typeof acc] = customInputs[label as keyof typeof customInputs]; | ||
| acc[slugify(label) as keyof typeof acc] = | ||
| customInputs[label as keyof typeof customInputs]; | ||
| return acc; | ||
| }, {}); | ||
| return { | ||
|
|
@@ -43,7 +46,11 @@ function getResponsesFromOldBooking( | |
| }; | ||
| } | ||
|
|
||
| async function getBooking(prisma: PrismaClient, uid: string, isSeatedEvent?: boolean) { | ||
| async function getBooking( | ||
| prisma: PrismaClient, | ||
| uid: string, | ||
| isSeatedEvent?: boolean | ||
| ) { | ||
| const rawBooking = await prisma.booking.findUnique({ | ||
| where: { | ||
| uid, | ||
|
|
@@ -80,6 +87,7 @@ async function getBooking(prisma: PrismaClient, uid: string, isSeatedEvent?: boo | |
| user: { | ||
| select: { | ||
| id: true, | ||
| username: true, | ||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -94,8 +102,12 @@ async function getBooking(prisma: PrismaClient, uid: string, isSeatedEvent?: boo | |
| if (booking) { | ||
| // @NOTE: had to do this because Server side cant return [Object objects] | ||
| // probably fixable with json.stringify -> json.parse | ||
| booking["startTime"] = (booking?.startTime as Date)?.toISOString() as unknown as Date; | ||
| booking["endTime"] = (booking?.endTime as Date)?.toISOString() as unknown as Date; | ||
| booking["startTime"] = ( | ||
| booking?.startTime as Date | ||
| )?.toISOString() as unknown as Date; | ||
| booking["endTime"] = ( | ||
| booking?.endTime as Date | ||
| )?.toISOString() as unknown as Date; | ||
| } | ||
|
|
||
| return booking; | ||
|
|
@@ -115,7 +127,9 @@ export const getBookingWithResponses = < | |
| ) => { | ||
| return { | ||
| ...booking, | ||
| responses: isSeatedEvent ? booking.responses : booking.responses || getResponsesFromOldBooking(booking), | ||
| responses: isSeatedEvent | ||
| ? booking.responses | ||
| : booking.responses || getResponsesFromOldBooking(booking), | ||
| } as Omit<T, "responses"> & { responses: Record<string, any> }; | ||
| }; | ||
|
|
||
|
|
@@ -130,9 +144,15 @@ export const getBookingForReschedule = async (uid: string, userId?: number) => { | |
| select: { | ||
| id: true, | ||
| userId: true, | ||
| user: { | ||
| select: { | ||
| organizationId: true, | ||
| }, | ||
| }, | ||
| eventType: { | ||
| select: { | ||
| seatsPerTimeSlot: true, | ||
| teamId: true, | ||
| hosts: { | ||
| select: { | ||
| userId: true, | ||
|
|
@@ -152,7 +172,10 @@ export const getBookingForReschedule = async (uid: string, userId?: number) => { | |
| // If no booking is found via the uid, it's probably a booking seat | ||
| // that its being rescheduled, which we query next. | ||
| let attendeeEmail: string | null = null; | ||
| let bookingSeatData: { description?: string; responses: Prisma.JsonValue } | null = null; | ||
| let bookingSeatData: { | ||
| description?: string; | ||
| responses: Prisma.JsonValue; | ||
| } | null = null; | ||
| if (!theBooking) { | ||
| const bookingSeat = await prisma.bookingSeat.findFirst({ | ||
| where: { | ||
|
|
@@ -175,7 +198,10 @@ export const getBookingForReschedule = async (uid: string, userId?: number) => { | |
| }, | ||
| }); | ||
| if (bookingSeat) { | ||
| bookingSeatData = bookingSeat.data as unknown as { description?: string; responses: Prisma.JsonValue }; | ||
| bookingSeatData = bookingSeat.data as unknown as { | ||
| description?: string; | ||
| responses: Prisma.JsonValue; | ||
| }; | ||
| bookingSeatReferenceUid = bookingSeat.id; | ||
| rescheduleUid = bookingSeat.booking.uid; | ||
| attendeeEmail = bookingSeat.attendee.email; | ||
|
|
@@ -185,28 +211,57 @@ export const getBookingForReschedule = async (uid: string, userId?: number) => { | |
| // If we have the booking and not bookingSeat, we need to make sure the booking belongs to the userLoggedIn | ||
| // Otherwise, we return null here. | ||
| let hasOwnershipOnBooking = false; | ||
| if (theBooking && theBooking?.eventType?.seatsPerTimeSlot && bookingSeatReferenceUid === null) { | ||
| if ( | ||
| theBooking && | ||
| theBooking?.eventType?.seatsPerTimeSlot && | ||
| bookingSeatReferenceUid === null | ||
| ) { | ||
| const isOwnerOfBooking = theBooking.userId === userId; | ||
|
|
||
| const isHostOfEventType = theBooking?.eventType?.hosts.some((host) => host.userId === userId); | ||
| const isHostOfEventType = theBooking?.eventType?.hosts.some( | ||
| (host) => host.userId === userId | ||
| ); | ||
|
|
||
| const isUserIdInBooking = theBooking.userId === userId; | ||
|
|
||
| if (!isOwnerOfBooking && !isHostOfEventType && !isUserIdInBooking) return null; | ||
| let hasOrgAccess = false; | ||
| if (userId && theBooking.user?.organizationId) { | ||
| const permissionCheckService = new PermissionCheckService(); | ||
| hasOrgAccess = await permissionCheckService.checkPermission({ | ||
| userId, | ||
| teamId: theBooking.user.organizationId, | ||
| permission: "booking.readOrgBookings", | ||
| fallbackRoles: [MembershipRole.OWNER, MembershipRole.ADMIN], | ||
| }); | ||
| } | ||
|
|
||
| if ( | ||
| !isOwnerOfBooking && | ||
| !isHostOfEventType && | ||
| !isUserIdInBooking && | ||
| !hasOrgAccess | ||
| ) | ||
| return null; | ||
| hasOwnershipOnBooking = true; | ||
| } | ||
|
|
||
| // If we don't have a booking and no rescheduleUid, the ID is invalid, | ||
| // and we return null here. | ||
| if (!theBooking && !rescheduleUid) return null; | ||
|
|
||
| const booking = await getBooking(prisma, rescheduleUid || uid, bookingSeatReferenceUid ? true : false); | ||
| const booking = await getBooking( | ||
| prisma, | ||
| rescheduleUid || uid, | ||
| bookingSeatReferenceUid ? true : false | ||
| ); | ||
|
|
||
| if (!booking) return null; | ||
|
|
||
| if (bookingSeatReferenceUid) { | ||
| booking["description"] = bookingSeatData?.description ?? null; | ||
| booking["responses"] = bookingResponsesDbSchema.parse(bookingSeatData?.responses ?? {}); | ||
| booking["responses"] = bookingResponsesDbSchema.parse( | ||
| bookingSeatData?.responses ?? {} | ||
| ); | ||
| } | ||
| return { | ||
| ...booking, | ||
|
|
@@ -244,6 +299,7 @@ export const getBookingForSeatedEvent = async (uid: string) => { | |
| user: { | ||
| select: { | ||
| id: true, | ||
| username: true, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for rescheduling its better to use the host username that we get from get-booking |
||
| }, | ||
| }, | ||
| }, | ||
|
|
@@ -293,6 +349,7 @@ export const getMultipleDurationValue = ( | |
| defaultValue: number | ||
| ) => { | ||
| if (!multipleDurationConfig) return null; | ||
| if (multipleDurationConfig.includes(Number(queryDuration))) return Number(queryDuration); | ||
| if (multipleDurationConfig.includes(Number(queryDuration))) | ||
| return Number(queryDuration); | ||
| return defaultValue; | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sean-brydon we use pbac now to check if user is org admin or not