-
Notifications
You must be signed in to change notification settings - Fork 11.6k
fix(reschedule): respect availability when rescheduling (#16378) #24127
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
base: main
Are you sure you want to change the base?
fix(reschedule): respect availability when rescheduling (#16378) #24127
Conversation
WalkthroughAdds server-side logic to derive a current session user (from rescheduleUid/email or from the request session via a dynamic session middleware import). If a distinct session user is found, the code obtains that user’s availability and intersects it with each organizer’s availability (respecting oooExcludedDateRanges) using the date-ranges intersection utility; if the session user has no availability the aggregated availability becomes empty. Adds end-to-end tests for organizer vs session-user intersection and organizer-only availability (fixed time, Asia/Kolkata). Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@sujal12344 is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
|
|
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.
Actionable comments posted: 3
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/web/test/lib/availability-intersection.test.ts(1 hunks)packages/trpc/server/routers/viewer/slots/util.ts(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/trpc/server/routers/viewer/slots/util.tsapps/web/test/lib/availability-intersection.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
packages/trpc/server/routers/viewer/slots/util.tsapps/web/test/lib/availability-intersection.test.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/trpc/server/routers/viewer/slots/util.tsapps/web/test/lib/availability-intersection.test.ts
🧠 Learnings (1)
📚 Learning: 2025-09-23T08:00:07.619Z
Learnt from: hariombalhara
PR: calcom/cal.com#23918
File: packages/features/schedules/lib/use-schedule/useTimesForSchedule.test.ts:16-23
Timestamp: 2025-09-23T08:00:07.619Z
Learning: In calcom/cal.com test files, particularly packages/features/schedules/lib/use-schedule/useTimesForSchedule.test.ts, the TIMEZONE_OFFSETS mapping is intentionally limited to only UTC variants and Asia/Kolkata. This is by design and should not be flagged as incomplete in future reviews (confirmed by maintainer hariombalhara).
Applied to files:
apps/web/test/lib/availability-intersection.test.ts
🧬 Code graph analysis (2)
packages/trpc/server/routers/viewer/slots/util.ts (3)
packages/trpc/server/middlewares/sessionMiddleware.ts (2)
getSession(90-94)getUserFromSession(19-86)packages/lib/date-ranges.ts (1)
intersect(354-416)packages/lib/getAggregatedAvailability.ts (1)
getAggregatedAvailability(25-74)
apps/web/test/lib/availability-intersection.test.ts (2)
packages/lib/di/containers/AvailableSlots.ts (1)
getAvailableSlotsService(49-51)apps/web/test/utils/bookingScenario/bookingScenario.ts (4)
getOrganizer(1520-1579)TestData(1239-1511)getScenarioData(1581-1667)createBookingScenario(978-1009)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Install dependencies / Yarn install & cache
- GitHub Check: Codacy Static Code Analysis
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.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
apps/web/test/lib/availability-intersection.test.ts(1 hunks)packages/trpc/server/routers/viewer/slots/util.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/web/test/lib/availability-intersection.test.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
packages/trpc/server/routers/viewer/slots/util.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
packages/trpc/server/routers/viewer/slots/util.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
packages/trpc/server/routers/viewer/slots/util.ts
🧠 Learnings (2)
📚 Learning: 2025-09-12T11:23:34.158Z
Learnt from: hariombalhara
PR: calcom/cal.com#23736
File: packages/features/bookings/lib/reschedule/determineReschedulePreventionRedirect.ts:73-84
Timestamp: 2025-09-12T11:23:34.158Z
Learning: In the Cal.com codebase, the forceRescheduleForCancelledBooking flag historically affects both CANCELLED and REJECTED booking statuses, despite its name suggesting it should only affect cancelled bookings. This behavior existed before PR #23736 and was preserved during the refactoring.
Applied to files:
packages/trpc/server/routers/viewer/slots/util.ts
📚 Learning: 2025-09-03T09:52:51.182Z
Learnt from: hariombalhara
PR: calcom/cal.com#23541
File: packages/features/bookings/lib/di/modules/RegularBookingServiceModule.ts:22-28
Timestamp: 2025-09-03T09:52:51.182Z
Learning: The IBookingServiceDependencies interface in packages/features/bookings/lib/handleNewBooking.ts contains 6 properties: cacheService, checkBookingAndDurationLimitsService, prismaClient, bookingRepository, featuresRepository, and checkBookingLimitsService. This interface is used by RegularBookingService and matches the depsMap structure in RegularBookingServiceModule.
Applied to files:
packages/trpc/server/routers/viewer/slots/util.ts
🧬 Code graph analysis (1)
packages/trpc/server/routers/viewer/slots/util.ts (3)
packages/trpc/server/middlewares/sessionMiddleware.ts (2)
getSession(90-94)getUserFromSession(19-86)packages/lib/date-ranges.ts (1)
intersect(354-416)packages/lib/getAggregatedAvailability.ts (1)
getAggregatedAvailability(25-74)
🔇 Additional comments (2)
packages/trpc/server/routers/viewer/slots/util.ts (2)
11-11: LGTM: import for dynamic event defaultsImporting getDefaultEvent here is appropriate for the dynamic event path.
976-996: Don’t rely on input.email; derive the booker from rescheduleUidUsing input.email to identify the user whose availability should be intersected is fragile and can still select the host when they’re rescheduling, causing the original bug to persist. Resolve the invitee/booker directly from the booking referenced by input.rescheduleUid (grab attendees; pick the Cal.com user among them if any). If no Cal.com user exists, skip intersection as before.
Minimal change: move “who to intersect with” resolution to later (right before intersection) and derive from booking. Example replacement for this block (compute only a placeholder here and resolve after hosts/availability are known):
- // Extract current session user from context or from reschedule/booking context - let currentSessionUser: { id: number; email: string } | null = null; - - // First, try to get user from reschedule context (for reschedule scenarios) - if (input.rescheduleUid && input.email) { - ... - } + // Placeholder; we’ll resolve the intersect user later (post host availability) + let intersectUser: { id: number; email: string } | null = null;Then, inside the intersection section (see separate comment), resolve intersectUser via bookingRepo using input.rescheduleUid and only fall back to input.email if needed. This ensures we truly intersect with the invitee when the host is rescheduling.
|
@pumfleet @anikdhabal Could you please take a look when you get a chance? |
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.
Actionable comments posted: 0
🧹 Nitpick comments (5)
apps/web/test/lib/availability-intersection.test.ts (5)
17-17: Remove commented-out code.The commented-out
console.logshould be removed to keep the codebase clean.Apply this diff:
describe("User Availability Intersection Tests", () => { const availableSlotsService = getAvailableSlotsService(); - // console.log({availableSlotsService}) setupAndTeardown();
140-153: Consider using dayjs timezone plugin instead of manual offset.The code manually adds 5.5 hours to convert UTC to IST. While this works for tests with fixed system time, using the dayjs timezone plugin would be more robust and clearer. This would also eliminate the repeated conversion logic.
Example refactor (requires timezone plugin):
import timezone from '@calcom/dayjs/plugin/timezone'; import utc from '@calcom/dayjs/plugin/utc'; dayjs.extend(utc); dayjs.extend(timezone); // Then use: const slotTime = dayjs.utc(slot.time).tz("Asia/Kolkata"); const slotHour = slotTime.hour();Or create a helper function for the current approach:
const toIST = (utcTime: string) => dayjs(utcTime).utc().add(5.5, "hours"); // Usage: const slotTime = toIST(slot.time); const slotHour = slotTime.hour();
154-161: Remove or uncomment diagnostic code.The commented-out console.log contains useful diagnostic information. Either remove it entirely if not needed, or uncomment it if it's valuable for debugging test failures.
166-170: Consider removing console.log statements.Active console.log statements in tests can create noise in test output. Consider removing them or converting to proper test logging if needed for debugging.
258-258: Consider removing console.log statement.Similar to the first test, this console.log can create noise in test output.
Apply this diff:
expect(morningSlots.length).toBeGreaterThan(0); expect(afternoonSlots.length).toBeGreaterThan(0); - - console.log("Full organizer availability slots:", slotsForDate.length); });
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/web/test/lib/availability-intersection.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
**/*.ts: For Prisma queries, only select data you need; never useinclude, always useselect
Ensure thecredential.keyfield is never returned from tRPC endpoints or APIs
Files:
apps/web/test/lib/availability-intersection.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/review.mdc)
Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js
.utc()in hot paths like loops
Files:
apps/web/test/lib/availability-intersection.test.ts
**/*.{ts,tsx,js,jsx}
⚙️ CodeRabbit configuration file
Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.
Files:
apps/web/test/lib/availability-intersection.test.ts
🧠 Learnings (2)
📚 Learning: 2025-09-12T11:23:34.158Z
Learnt from: hariombalhara
PR: calcom/cal.com#23736
File: packages/features/bookings/lib/reschedule/determineReschedulePreventionRedirect.ts:73-84
Timestamp: 2025-09-12T11:23:34.158Z
Learning: The test file packages/features/bookings/lib/reschedule/determineReschedulePreventionRedirect.test.ts explicitly documents on line 236 that the current behavior of forceRescheduleForCancelledBooking affecting both CANCELLED and REJECTED bookings is known to be incorrect, but is preserved as "Current Behavior" for backward compatibility. The test comment states the expected behavior should be that REJECTED bookings redirect to booking details even when forceRescheduleForCancelledBooking=true.
Applied to files:
apps/web/test/lib/availability-intersection.test.ts
📚 Learning: 2025-09-23T08:00:07.619Z
Learnt from: hariombalhara
PR: calcom/cal.com#23918
File: packages/features/schedules/lib/use-schedule/useTimesForSchedule.test.ts:16-23
Timestamp: 2025-09-23T08:00:07.619Z
Learning: In calcom/cal.com test files, particularly packages/features/schedules/lib/use-schedule/useTimesForSchedule.test.ts, the TIMEZONE_OFFSETS mapping is intentionally limited to only UTC variants and Asia/Kolkata. This is by design and should not be flagged as incomplete in future reviews (confirmed by maintainer hariombalhara).
Applied to files:
apps/web/test/lib/availability-intersection.test.ts
🧬 Code graph analysis (1)
apps/web/test/lib/availability-intersection.test.ts (2)
packages/features/di/containers/AvailableSlots.ts (1)
getAvailableSlotsService(49-51)apps/web/test/utils/bookingScenario/bookingScenario.ts (4)
getOrganizer(1539-1598)TestData(1258-1530)getScenarioData(1600-1688)createBookingScenario(997-1028)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Linters / lint
- GitHub Check: Tests / Unit
- GitHub Check: Type check / check-types
🔇 Additional comments (2)
apps/web/test/lib/availability-intersection.test.ts (2)
163-164: Assertions correctly validate intersection behavior.The test properly asserts that intersection slots exist and no slots fall outside the intersection window. This validates that the availability intersection logic works as expected when both organizer and session user are present.
234-256: Test properly validates organizer-only availability.The test correctly asserts that when no session user context exists, the full organizer availability (10 AM - 2 PM IST) is shown. The test also validates that slots exist throughout both the morning and afternoon windows, ensuring comprehensive coverage of the availability range.
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.
2 issues found across 2 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="packages/trpc/server/routers/viewer/slots/util.ts">
<violation number="1" location="packages/trpc/server/routers/viewer/slots/util.ts:994">
Rule violated: **Avoid Logging Sensitive Information**
This debug log writes the user's email address to application logs, violating the "Avoid Logging Sensitive Information" rule. Strip the email from the log payload to keep PII out of logs.</violation>
<violation number="2" location="packages/trpc/server/routers/viewer/slots/util.ts:1010">
Rule violated: **Avoid Logging Sensitive Information**
This debug log records the session user's email address, breaching the "Avoid Logging Sensitive Information" rule. Remove the email field (or otherwise redact it) before logging to avoid leaking PII.</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
- Ask questions if you need clarification on any suggestion
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
What does this PR do?
This PR fixes the issue where rescheduling a booking did not respect the availability of the user who originally booked the meeting.
Now, when a host reschedules, the system correctly checks both participants’ availability before confirming the new time.
Visual Demo (For contributors especially)
Before (current behavior)
When rescheduling, only the invitee’s (user_B) availability is considered. The availability of the host (user_A) is ignored.
User A availability
User B availability
Only user_B availability is respected — host availability is ignored
After (fixed behavior)
When rescheduling, both the host (user_A) and invitee (user_B) availabilities are checked, and only common available times are shown.
User A availability
User B availability
Both availabilities are respected when rescheduling
Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
pnpm install && pnpm dev).Checklist