Skip to content

Conversation

@sean-brydon
Copy link
Member

@sean-brydon sean-brydon commented Jul 28, 2025

What We Did

I provided a comprehensive PR Summary for implementing PBAC
(Permission-Based Access Control) "manage" permissions in the
Cal.com codebase. This was a detailed documentation of a
completed feature implementation.

Key Implementation Details Covered

Database & Schema Changes

• Migration file:
packages/prisma/migrations/20250728091301_add_manage_permissions_to_default_roles/migration.
sql
• Added 4 new "manage" permissions to admin roles for: roles,
event types, teams, and bookings

Core Logic Files Modified

• Permission Registry:
packages/features/pbac/domain/types/permission-registry.ts
• Added Manage = "manage" to CrudAction enum
• Defined organization-scoped manage permissions
• Permission Service:
packages/features/pbac/services/permission-check.service.ts
• Enhanced 3 key methods: getResourcePermissions(),
hasPermission(), hasPermissions()
• Implemented automatic permission expansion and hierarchical
fallback logic

Testing & Localization

• Test file:
packages/features/pbac/services/tests/permission-check.
service.test.ts (6 new test cases, 30 total passing)
• i18n file: apps/web/public/static/locales/en/common.json (79
PBAC strings added)

Current Status

• Complete feature implementation with manage permissions
allowing organization administrators to have hierarchical
control over all actions within specific resources
• All tests passing, migration applied, comprehensive
documentation provided

What We're Working On

This appears to be a completed feature summary/documentation
rather than active development work.

@sean-brydon sean-brydon requested a review from a team July 28, 2025 09:42
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 28, 2025

Walkthrough

This change introduces a new "manage" permission action across the application’s permission system. The CrudAction enum is extended to include "Manage," and the permission registry is updated to define "manage" permissions for roles, event types, teams, and bookings, scoped at the organization level. The English localization strings are updated to clarify that these permissions apply "across organization teams." The PermissionCheckService logic is updated so that holding a "manage" permission for a resource implicitly grants all subordinate permissions for that resource, both at the team and organization levels. Comprehensive tests are added to verify this expanded permission logic. A database migration script adds the new "manage" permissions to the admin role for the relevant resources.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

  • Complexity: Moderate. The changes span backend logic, permission registry, localization, tests, and a migration script, but are conceptually unified and do not introduce new APIs or complex algorithms.
  • Review scope: Requires careful review of permission expansion logic, test coverage for new behaviors, and correctness of migration data. The changes are isolated and well-structured, with no modifications to public interfaces.

Possibly related PRs

  • fix: (pbac) edit sheet readonly to all to readonly #22672: Modifies the getResourcePermissionLevel function to handle the global wildcard "*.*" permission, while this PR adds explicit handling for the "manage" permission in the same function; both affect permission level determination logic.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50da7d7 and 7055b10.

📒 Files selected for processing (2)
  • apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/__tests__/usePermissions.test.ts (1 hunks)
  • apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/usePermissions.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code. Functions like .add, .diff, .isBefore, and .isAfter are slow, especially in timezone mode. Prefer .utc() for better performance. Where possible, replace with native Date and direct .valueOf() comparisons for faster execution. Recommend using native methods or Day.js .utc() consistently in hot paths like loops.

Files:

  • apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/__tests__/usePermissions.test.ts
  • apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/usePermissions.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (3)
apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/__tests__/usePermissions.test.ts (1)

48-58: LGTM! Comprehensive test coverage for "manage" permission.

The test cases properly validate the new "manage" permission behavior where having "manage" permission grants "all" access level. The tests cover both standalone "manage" permission and "manage" with other permissions present.

apps/web/app/(use-page-wrapper)/settings/(settings-layout)/organizations/roles/_components/usePermissions.ts (2)

54-69: LGTM! Correct implementation of hierarchical "manage" permission.

The implementation properly handles the new "manage" permission by:

  1. Hierarchical checking: Checks "manage" permission after global permissions but before individual CRUD permissions
  2. Proper filtering: Excludes "manage" from individual CRUD permission checks to prevent interference
  3. Clear logic flow: Maintains the existing permission evaluation order while integrating the new functionality

The variable naming (crudPermissions, hasAllCrudPerms) is descriptive and the filtering logic correctly handles both internal keys and the "manage" permission.


107-109: Verify "manage" permission handling in toggle functions.

The toggleResourcePermissionLevel function correctly includes "manage" permissions when toggling to "all" level since it filters only internal keys (starting with "_"). This ensures that when a user selects "all" permissions for a resource, the "manage" permission is included along with other CRUD permissions.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/remove-fallback-pbac-manage

🪧 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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • 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.

@graphite-app graphite-app bot requested a review from a team July 28, 2025 09:42
@github-actions github-actions bot added the ❗️ migrations contains migration files label Jul 28, 2025
@keithwillcode keithwillcode added consumer core area: core, team members only labels Jul 28, 2025
@dosubot dosubot bot added enterprise area: enterprise, audit log, organisation, SAML, SSO i18n area: i18n, translations labels Jul 28, 2025
@graphite-app
Copy link

graphite-app bot commented Jul 28, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (07/28/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add ready-for-e2e label" took an action on this PR • (07/28/25)

1 label was added to this PR based on Keith Williams's automation.

@vercel
Copy link

vercel bot commented Jul 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Jul 28, 2025 10:19am
cal-eu ⬜️ Ignored (Inspect) Jul 28, 2025 10:19am

@sean-brydon sean-brydon marked this pull request as draft July 28, 2025 09:54
Copy link
Contributor

@emrysal emrysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, lgtm

@emrysal emrysal enabled auto-merge (squash) July 28, 2025 11:29
@emrysal emrysal merged commit 30061c0 into main Jul 28, 2025
60 of 62 checks passed
@emrysal emrysal deleted the fix/remove-fallback-pbac-manage branch July 28, 2025 11:49
sean-brydon added a commit that referenced this pull request Aug 11, 2025
This reverts commit 30061c0.

Removes the manage permission concept and fallback logic to simplify
permission checking back to direct role-based checks.
CarinaWolli pushed a commit that referenced this pull request Aug 26, 2025
#23013)

* Revert "fix: remove fallback permssions on organization Id. (#22769)"

This reverts commit 30061c0.

Removes the manage permission concept and fallback logic to simplify
permission checking back to direct role-based checks.

* remove manage from workflows

* fix type error and remove manage from components
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

consumer core area: core, team members only enterprise area: enterprise, audit log, organisation, SAML, SSO i18n area: i18n, translations ❗️ migrations contains migration files ready-for-e2e

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants