Skip to content

feat: implement member-based booking limits for organization admins#23413

Closed
Devanshusharma2005 wants to merge 4 commits intomainfrom
devin/1756355382-member-booking-limits
Closed

feat: implement member-based booking limits for organization admins#23413
Devanshusharma2005 wants to merge 4 commits intomainfrom
devin/1756355382-member-booking-limits

Conversation

@Devanshusharma2005
Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 commented Aug 28, 2025

What does this PR do?

Implements member-based booking limits controlled by organization admins as described in GitHub issue #22626. This feature allows org admins to set booking limits for individual members that apply across all their event types (both personal and team). The limits are enforced during booking creation and use the existing IntervalLimitsManager UI component.

Key Changes

Database Schema

  • Added bookingLimits JSON field to the Membership table to store per-member booking limits

UI Components

  • Added booking limits section to organization member edit form (/settings/organizations/<slug>/members)
  • Reuses existing IntervalLimitsManager component from event type settings
  • Added translation string for member booking limits description

Backend Implementation

  • Validation: Added validateIntervalLimitOrder validation to ensure limits are in ascending order (day ≤ week ≤ month ≤ year)
  • Persistence: Updated updateUser tRPC endpoint to save booking limits to membership record
  • Data Access: Updated getUser and listMembers handlers to include booking limits in responses
  • Enforcement: Added booking limit checks in handleNewBooking.ts for team event bookings

How should this be tested?

Environment Setup

  • Ensure you have an organization with admin permissions
  • Create test members in the organization
  • Have event types set up (both personal and team event types)

Test Scenarios

  1. Setting Booking Limits:

    • Navigate to /settings/organizations/<slug>/members
    • Edit a member and set booking limits (e.g., 2 per day, 5 per week)
    • Verify limits are saved and displayed correctly
  2. Booking Enforcement - Team Events:

    • Set a low limit (e.g., 1 per day) for a team member
    • Try to book multiple slots for that member on the same day
    • Should be blocked after exceeding the limit
  3. Validation Testing:

    • Try setting invalid limits (e.g., week limit < day limit)
    • Should show "Booking limits must be in ascending order" error
  4. Authorization Testing:

    • Verify only organization admins can set member booking limits
    • Non-admin users should not see the booking limits UI

⚠️ Important Areas for Review

1. Booking Enforcement Completeness

The current implementation only checks member booking limits for team events (eventType.team?.id). Need to verify if this also needs to apply to personal event types, as the requirements mention "all event types (both personal and team)".

2. Type Safety

There are type casts like organizerMembership.bookingLimits as IntervalLimit that should be validated for safety.

3. Database Migration

The migration adds a nullable JSON column. Verify existing membership records handle this gracefully.

4. Test Coverage

This is a complex feature affecting booking creation but has minimal test additions. Consider if more comprehensive test scenarios are needed.

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have checked if my changes generate no new warnings

Link to Devin session: https://app.devin.ai/sessions/10fea31e8ab14a28b8cf010cc3526d68
Requested by: @Devanshusharma2005

- Add bookingLimits Json field to Membership model in Prisma schema
- Create database migration for the new bookingLimits field
- Update organization updateUser tRPC endpoint to handle bookingLimits
- Add booking limits UI to organization member edit sheet using IntervalLimitsManager
- Extend booking enforcement logic to check member-level limits in handleNewBooking
- Update organization member data fetching to include bookingLimits
- Add translation string for booking limits member description
- Fix test data to include bookingLimits field

Resolves #22626

Co-Authored-By: Devanshu Sharma <devanshusharma658@gmail.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbit review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/1756355382-member-booking-limits

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added consumer Medium priority Created by Linear-GitHub Sync organizations area: organizations, orgs ❗️ migrations contains migration files labels Aug 28, 2025
@keithwillcode keithwillcode added the community-interns The team responsible for reviewing, testing and shipping low/medium community PRs label Aug 28, 2025
…mits

- Import validateIntervalLimitOrder from intervalLimits library
- Add validation logic similar to team booking limits
- Ensure booking limits are in ascending order (day ≤ week ≤ month ≤ year)
- Throw BAD_REQUEST error with descriptive message for invalid limits

This incorporates the key improvement from PR #23233 to maintain consistency
with existing team booking limits validation patterns.

Co-Authored-By: Devanshu Sharma <devanshusharma658@gmail.com>
@vercel
Copy link

vercel bot commented Aug 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
cal Ignored Ignored Aug 28, 2025 6:00am
cal-eu Ignored Ignored Aug 28, 2025 6:00am

- Remove unused isFormCreateEditAllowed import from formMutation.handler.ts
- Remove unused TRPCError import from formQuery.handler.ts
- Change MembershipRole from import to type import in permissions.ts

These changes were automatically applied by lint-staged during the previous commit.

Co-Authored-By: Devanshu Sharma <devanshusharma658@gmail.com>
…ests

- Fix validation logic to properly check ascending order of booking limits
- Add test coverage for validateIntervalLimitOrder function
- Ensure PER_DAY ≤ PER_WEEK ≤ PER_MONTH ≤ PER_YEAR validation works correctly
- Handle partial limits (e.g., only PER_DAY and PER_MONTH) properly

Co-Authored-By: Devanshu Sharma <devanshusharma658@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-interns The team responsible for reviewing, testing and shipping low/medium community PRs consumer Medium priority Created by Linear-GitHub Sync ❗️ migrations contains migration files organizations area: organizations, orgs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Member based limits controlled by org admins

2 participants