feat: check guest availability when host reschedules a booking#27968
feat: check guest availability when host reschedules a booking#27968MrLawrenceKwan wants to merge 1 commit intocalcom:mainfrom
Conversation
When a host reschedules a booking, check if any attendees are Cal.com users. If they are, fetch their existing bookings as busy times and filter available slots accordingly. This ensures the host can only reschedule to times that work for both parties, preventing conflicts with the guest's calendar. Changes: - UserRepository: add findUsersByEmails() to look up Cal.com users - BookingRepository: add findAcceptedBookingsByUserIdsOrEmails() - getUserAvailability: accept optional guestBusyTimes in initialData - slots/util: fetch guest busy times during reschedule flow Fixes calcom#16378 /claim calcom#16378
Graphite Automations"Send notification to Community team when bounty PR opened" took an action on this PR • (02/15/26)2 teammates were notified to this PR based on Keith Williams's automation. |
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/features/users/repositories/UserRepository.ts">
<violation number="1" location="packages/features/users/repositories/UserRepository.ts:289">
P2: findUsersByEmails ignores secondary emails and account status, so attendee lookups can miss valid users (secondary email) or include locked/unverified accounts in availability checks. This diverges from the established verified/secondary-email-aware lookup in the same repository and can skew reschedule availability.</violation>
</file>
Since this is your first cubic review, here's how it works:
- cubic automatically reviews your code and comments on bugs and improvements
- Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
- Add one-off context when rerunning by tagging
@cubic-dev-aiwith guidance or docs links (includingllms.txt) - Ask questions if you need clarification on any suggestion
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| const normalizedEmails = emails.map((e) => e.toLowerCase()); | ||
| return this.prismaClient.user.findMany({ | ||
| where: { | ||
| email: { in: normalizedEmails }, |
There was a problem hiding this comment.
P2: findUsersByEmails ignores secondary emails and account status, so attendee lookups can miss valid users (secondary email) or include locked/unverified accounts in availability checks. This diverges from the established verified/secondary-email-aware lookup in the same repository and can skew reschedule availability.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/features/users/repositories/UserRepository.ts, line 289:
<comment>findUsersByEmails ignores secondary emails and account status, so attendee lookups can miss valid users (secondary email) or include locked/unverified accounts in availability checks. This diverges from the established verified/secondary-email-aware lookup in the same repository and can skew reschedule availability.</comment>
<file context>
@@ -277,6 +277,26 @@ export class UserRepository {
+ const normalizedEmails = emails.map((e) => e.toLowerCase());
+ return this.prismaClient.user.findMany({
+ where: {
+ email: { in: normalizedEmails },
+ },
+ select: {
</file context>
MrLawrenceKwan
left a comment
There was a problem hiding this comment.
Thanks for the review! Regarding the findUsersByEmails observation:
This function intentionally does a simple primary email lookup for the reschedule guest availability check. The rationale:
- Guest emails come from the booking record — these are the emails guests used when booking, which would match their primary Cal.com email in the vast majority of cases
- False negatives are safe — if a guest's secondary email isn't matched, the reschedule simply won't check their availability (same as current behavior for non-Cal.com guests). The host can still reschedule.
- Account status filtering — locked/unverified accounts are edge cases that don't meaningfully affect availability checks for rescheduling
That said, if maintainers prefer using the verified/secondary-email-aware lookup pattern, I'm happy to update this to use findManyByEmailsWithEmailVerificationSettings instead. Let me know!
Ryukemeister
left a comment
There was a problem hiding this comment.
hi there, thanks for your contribution. can you please add relevant e2e tests for the PR, also attaching a visual demo would be really helpful. thanks!
What does this PR do?
When a host reschedules a booking, this PR checks if any attendees (guests) are Cal.com users. If they are, their existing bookings are fetched as busy times and included in the available slots calculation — ensuring the host can only reschedule to times that work for both parties.
Problem
Currently, when a host reschedules, the system doesn't check the guest's availability. If the guest is a Cal.com user, this can result in scheduling conflicts.
Solution (minimal, focused changes)
Design decisions
Files changed (4 files, +122 lines, -0 lines)
/claim #16378
Fixes #16378