fix: enforce slot interval during booking creation#29683
fix: enforce slot interval during booking creation#29683Shreyas2004wagh wants to merge 2 commits into
Conversation
|
Welcome to Cal.diy, @Shreyas2004wagh! Thanks for opening this pull request. A few things to keep in mind:
A maintainer will review your PR soon. Thanks for contributing! |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis change adds slot-start validation when checking user availability for new bookings. 🚥 Pre-merge checks | ✅ 5✅ 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/features/bookings/lib/handleNewBooking/ensureAvailableUsers.ts`:
- Around line 69-79: The slot-grid validation in ensureAvailableUsers currently
falls back to the submitted duration when computing frequency for getSlots,
which can let a tampered booking time use a different cadence than the event
type. Update the frequency source in ensureAvailableUsers to use only the
server-owned event-type cadence, referencing eventType.slotInterval and
eventType.length (or the approved server-side duration source), and keep
getSlots aligned with that configured grid instead of the request-derived
duration.
In `@packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts`:
- Around line 58-64: The timestamp construction in the date override test is
still anchored to the runner’s local timezone before converting to New York,
which can shift the date on some machines. Update the setup around
startDateTimeOrganizerTz to parse plus1DateString directly in newYorkTimeZone
using dayjs.tz(...) instead of chaining from dayjs(...).endOf("day").tz(...), so
the test always builds the timestamp in New York time.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 166f7080-4c34-4045-b5ec-702132e852cb
📒 Files selected for processing (3)
packages/features/bookings/lib/handleNewBooking/ensureAvailableUsers.tspackages/features/bookings/lib/handleNewBooking/getEventTypesFromDB.tspackages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts
What changed
slotInterval,offsetStart, andshowOptimizedSlotswhen loading the event type for booking creation.Why
The booking UI respects the configured slot interval, but the booking creation path allowed users to modify the slot/start time in the request and book times that were inside availability but not part of the configured slot grid.
Fixes #14640
Proof
I reproduced the issue with a regression test before applying the fix.
Scenario:
slotInterval: 6010:00-12:0010:30-11:00Before this change, the booking was accepted because
10:30was inside availability even though it was not a valid generated slot.After this change, the same request is rejected with
NoAvailableUsersFound.Regression test added:
packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.tsTesting
node .yarn/releases/yarn-4.12.0.cjs vitest run packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts --reporter=verbosenode .yarn/releases/yarn-4.12.0.cjs type-check:ci --force --filter=@calcom/featuresnode .yarn/releases/yarn-4.12.0.cjs biome check --write packages/features/bookings/lib/handleNewBooking/ensureAvailableUsers.ts packages/features/bookings/lib/handleNewBooking/getEventTypesFromDB.ts packages/features/bookings/lib/handleNewBooking/test/date-overrides.test.ts