feat: implement global booking limits for users#25641
feat: implement global booking limits for users#25641Armadillidiid wants to merge 25 commits intocalcom:mainfrom
Conversation
|
@Armadillidiid is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details: |
There was a problem hiding this comment.
Pull request overview
This PR implements global booking limits for users, allowing them to set booking frequency caps (per day/week/month/year) across all their personal event types from the My Account settings page. The feature includes database schema changes, TRPC endpoints for fetching and updating limits, enforcement in both availability checks and booking creation, and a comprehensive test suite.
Key changes:
- Added
bookingLimitsJSON column to the User model with validation and enforcement logic - Implemented priority hierarchy where user global limits take precedence over event type limits for personal events, while team events remain isolated with their own team-level limits
- Created new "Booking limits" settings page under My Account with toggle and form controls for configuring the limits
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/prisma/schema.prisma | Added bookingLimits JSONB field to User model |
| packages/prisma/migrations/20250814170930_add_user_booking_limits/migration.sql | Migration to add bookingLimits column to users table |
| packages/trpc/server/routers/viewer/me/updateProfile.schema.ts | Added bookingLimits to profile update schema |
| packages/trpc/server/routers/viewer/me/updateProfile.handler.ts | Implemented validation and persistence of booking limits with error handling |
| packages/trpc/server/routers/viewer/me/get.handler.ts | Added bookingLimits retrieval and validation to user profile endpoint |
| packages/features/bookings/repositories/BookingRepository.ts | Added getAllAcceptedUserBookings method to query personal bookings for limit enforcement |
| packages/features/bookings/lib/checkBookingLimits.ts | Extended limit checking to support user-level limits with priority logic |
| packages/features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits.ts | Integrated global booking limits into booking creation flow for personal events |
| packages/features/busyTimes/lib/getBusyTimesFromLimits.ts | Added getBusyTimesFromGlobalBookingLimits to mark time slots as busy when limits are reached |
| packages/features/availability/lib/getUserAvailability.ts | Integrated global booking limits into availability calculation for personal events only |
| apps/web/modules/settings/my-account/booking-limits-view.tsx | New settings page view for managing global booking limits |
| apps/web/components/settings/GlobalBookingLimitsController.tsx | Form controller component with toggle, validation, and auto-save functionality |
| apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx | Added "booking_limits" navigation tab (removed "conferencing" tab - likely unintentional) |
| apps/web/public/static/locales/en/common.json | Added translation strings for global booking limits UI |
| packages/features/bookings/lib/handleNewBooking/test/global-booking-limits.integration-test.ts | Comprehensive integration tests covering all limit intervals, priority rules, and edge cases |
| apps/web/test/lib/checkBookingLimits.test.ts | Unit tests for limit checking service with priority hierarchy validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
packages/features/bookings/lib/handleNewBooking/test/global-booking-limits.integration-test.ts
Outdated
Show resolved
Hide resolved
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx
Show resolved
Hide resolved
packages/features/bookings/lib/handleNewBooking/checkBookingAndDurationLimits.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
4 issues found across 30 files
Prompt for AI agents (all 4 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/features/bookings/lib/handleNewBooking/test/global-booking-limits.integration-test.ts">
<violation number="1" location="packages/features/bookings/lib/handleNewBooking/test/global-booking-limits.integration-test.ts:430">
P3: Typo in comment: 'firth' should be 'fifth'.</violation>
</file>
<file name="apps/web/app/(use-page-wrapper)/settings/(settings-layout)/my-account/booking-limits/page.tsx">
<violation number="1" location="apps/web/app/(use-page-wrapper)/settings/(settings-layout)/my-account/booking-limits/page.tsx:25">
P2: Callback URL should redirect to the current page (`/settings/my-account/booking-limits`) after login, not `/settings/my-account/general`. Following the pattern from `general/page.tsx`, each page should redirect back to itself.</violation>
</file>
<file name="apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx">
<violation number="1" location="apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx:43">
P1: The `conferencing` settings tab is being replaced rather than having `booking_limits` added as a new entry. The conferencing page still exists at `/settings/my-account/conferencing/` but will no longer be accessible via the navigation menu. Consider adding `booking_limits` as an additional entry instead of replacing `conferencing`.</violation>
</file>
<file name="packages/platform/libraries/tsconfig.json">
<violation number="1" location="packages/platform/libraries/tsconfig.json:15">
P2: Path mapping has mismatched wildcard syntax. The key `@calcom/web/public` lacks a wildcard but the value has `*`. For sub-path imports to resolve, both should use wildcards: `"@calcom/web/public/*": ["../../../apps/web/public/*"]`.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
packages/features/bookings/lib/handleNewBooking/test/global-booking-limits.integration-test.ts
Outdated
Show resolved
Hide resolved
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/my-account/booking-limits/page.tsx
Outdated
Show resolved
Hide resolved
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/SettingsLayoutAppDirClient.tsx
Show resolved
Hide resolved
|
This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active. |
|
This PR has been marked as stale due to inactivity. If you're still working on it or need any help, please let us know or update the PR to keep it active. |
This fixes Next.js module resolution error where bundled code couldn't resolve translation files at runtime. For more info: vercel/turborepo#4979 (comment)
- Added a new "Booking Limits" tab and page under My Account settings. - Moved global booking limits UI from General to the new page. - Updated i18n strings for booking limits and added a global description. - Removed booking limits controller from the General settings view.
Global user-level booking limits now apply exclusively to personal events. Team events are governed by their own team booking limits, preventing unintended restriction by user-level limits.
0b72cf4 to
5fde653
Compare
Devin AI is resolving merge conflictsThis PR has merge conflicts with the Devin will:
If you prefer to resolve conflicts manually, you can close the Devin session and handle it yourself. |
Devin AI is resolving merge conflictsThis PR has merge conflicts with the Devin will:
If you prefer to resolve conflicts manually, you can close the Devin session and handle it yourself. |
What does this PR do?
Implements global booking limits that allows users to limit the total number of bookings for user event types from settings page.
Visual Demo
calcom-global-booking-limits-demo.mp4
Mandatory Tasks
How should this be tested?
Test Steps
Enable Global Booking Limits
Test Limit Enforcement
POST /api/book/eventand verify it fails.Test Priority Hierarchy
Test Rescheduling
Expected Behavior
Unit Tests
yarn test checkBookingLimits.test.tsIntegration Tests
yarn test global-booking-limits.integration-test.ts -- --integrationTestsOnlySummary by cubic
Adds global user-level booking limits across a user's personal event types, with a dedicated My Account page and backend enforcement in availability and individual booking creation. Delivers CAL-1724 by blocking new bookings and hiding slots once a user's daily/weekly/monthly/yearly cap is reached.
New Features
Migration
Written for commit 5fde653. Summary will update automatically on new commits.