Skip to content

Conversation

@knoid
Copy link
Contributor

@knoid knoid commented Aug 16, 2025

Description

A custom field in the Administrator entity wouldn't show up in the Administrator's profile if the requiresPermission included Permission.Owner. This fix assumes that whoever is in the profile view is the owner so checking for the Owner permission should return true.

Breaking changes

Does this PR include any breaking changes we should be aware of? No.

Screenshots

You can add screenshots here if applicable.

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Summary by CodeRabbit

  • New Features
    • Profile: Custom fields now honor owner-specific permissions. Users can view and edit fields designated for “Owner” when managing their own profile, while non-owners won’t see these fields.
    • Permissions: Enhanced permission checks to support owner-aware access across custom fields, expanding what eligible users can see without affecting existing non-owner visibility.

@vercel
Copy link

vercel bot commented Aug 16, 2025

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

Project Deployment Preview Updated (UTC)
docs Ready Ready Preview Aug 16, 2025 11:46pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 16, 2025

Walkthrough

Introduces an isOwner boolean parameter to permission checks. Updates BaseDetailComponent.getCustomFieldConfig to pass isOwner to PermissionsService.userHasPermissions. ProfileComponent now calls getCustomFieldConfig('Administrator', true). A minor formatting comma is added in ProfileComponent’s @component decorator.

Changes

Cohort / File(s) Summary
Owner-aware permissions propagation
packages/admin-ui/src/lib/core/src/common/base-detail.component.ts, packages/admin-ui/src/lib/core/src/providers/permissions/permissions.service.ts, packages/admin-ui/src/lib/settings/src/components/profile/profile.component.ts
- Add optional isOwner param to getCustomFieldConfig and forward it to permission checks.
- Extend PermissionsService.userHasPermissions(requiredPermissions, isOwner) to allow Permission.Owner when isOwner is true; default remains false.
- ProfileComponent calls getCustomFieldConfig('Administrator', true).
- Minor formatting: trailing comma in @component options.

Sequence Diagram(s)

sequenceDiagram
    participant ProfileComponent
    participant BaseDetailComponent
    participant PermissionsService

    ProfileComponent->>BaseDetailComponent: getCustomFieldConfig('Administrator', true)
    BaseDetailComponent->>PermissionsService: userHasPermissions(requiredPermissions, isOwner=true)
    PermissionsService-->>BaseDetailComponent: boolean (includes Owner check)
    BaseDetailComponent-->>ProfileComponent: filtered CustomFieldConfig[]
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


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 @coderabbitai in a new review comment at the desired location with your query.
  • 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 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 @coderabbitai help to get the list of available commands.

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

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.

@sonarqubecloud
Copy link

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (2)
packages/admin-ui/src/lib/core/src/providers/permissions/permissions.service.ts (1)

33-40: Document the new isOwner semantics for future readers

A short TSDoc will make the OR semantics and the special-case for Permission.Owner explicit.

Apply this diff to add a docblock:

-    userHasPermissions(requiredPermissions: Array<string | Permission>, isOwner = false): boolean {
+    /**
+     * Returns true if the user has at least one of the required permissions.
+     * Special-case: if `Permission.Owner` is among the required permissions and
+     * `isOwner` is true (i.e. the current user is the resource owner in context),
+     * this method returns true as well.
+     */
+    userHasPermissions(requiredPermissions: Array<string | Permission>, isOwner = false): boolean {
         for (const perm of requiredPermissions) {
             if (this.currentUserPermissions.includes(perm) || (perm === Permission.Owner && isOwner)) {
                 return true;
             }
         }
         return false;
     }
packages/admin-ui/src/lib/core/src/common/base-detail.component.ts (1)

153-161: Clarify the new parameter in method docs

Given this method is used broadly by detail components, documenting when to pass isOwner will prevent misuse.

Apply this diff to add TSDoc:

-    protected getCustomFieldConfig(
+    /**
+     * Returns the custom field config for an entity key, filtered by the current user's permissions.
+     * If `isOwner` is true, fields that require `Permission.Owner` will be included.
+     */
+    protected getCustomFieldConfig(
         key: Exclude<keyof CustomFields, '__typename'>,
         isOwner = false,
     ): CustomFieldConfig[] {
         return this.serverConfigService.getCustomFieldsFor(key).filter(f => {
             if (f.requiresPermission?.length) {
-                return this.permissionsService.userHasPermissions(f.requiresPermission, isOwner);
+                return this.permissionsService.userHasPermissions(f.requiresPermission, isOwner);
             }
             return true;
         });
     }
📜 Review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f5237f0 and b7c5d95.

📒 Files selected for processing (3)
  • packages/admin-ui/src/lib/core/src/common/base-detail.component.ts (1 hunks)
  • packages/admin-ui/src/lib/core/src/providers/permissions/permissions.service.ts (1 hunks)
  • packages/admin-ui/src/lib/settings/src/components/profile/profile.component.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
packages/admin-ui/src/lib/core/src/providers/permissions/permissions.service.ts (1)
packages/core/src/index.ts (1)
  • Permission (6-6)
packages/admin-ui/src/lib/core/src/common/base-detail.component.ts (1)
packages/admin-ui/src/lib/core/src/common/generated-types.ts (2)
  • CustomFields (1365-1402)
  • CustomFieldConfig (1359-1359)
packages/admin-ui/src/lib/settings/src/components/profile/profile.component.ts (1)
packages/admin-ui/src/lib/core/src/common/generated-types.ts (1)
  • GetProfileDetailDocument (9561-9561)
⏰ 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). (20)
  • GitHub Check: e2e tests (22.x, mariadb)
  • GitHub Check: e2e tests (20.x, postgres)
  • GitHub Check: e2e tests (22.x, sqljs)
  • GitHub Check: e2e tests (20.x, sqljs)
  • GitHub Check: unit tests (24.x)
  • GitHub Check: codegen / codegen
  • GitHub Check: build (24.x)
  • GitHub Check: build (22.x)
  • GitHub Check: unit tests (22.x)
  • GitHub Check: unit tests (20.x)
  • GitHub Check: build (20.x)
  • GitHub Check: publish_install (macos-latest, 22.x)
  • GitHub Check: publish_install (windows-latest, 20.x)
  • GitHub Check: publish_install (windows-latest, 22.x)
  • GitHub Check: publish_install (macos-latest, 24.x)
  • GitHub Check: publish_install (ubuntu-latest, 24.x)
  • GitHub Check: publish_install (windows-latest, 24.x)
  • GitHub Check: publish_install (ubuntu-latest, 20.x)
  • GitHub Check: publish_install (macos-latest, 20.x)
  • GitHub Check: publish_install (ubuntu-latest, 22.x)
🔇 Additional comments (3)
packages/admin-ui/src/lib/core/src/providers/permissions/permissions.service.ts (1)

33-40: Owner-aware permission check is correctly scoped and backward-compatible

Adding the isOwner flag and short-circuiting when Permission.Owner is present addresses the visibility bug without impacting existing call sites (default false). Good, minimal fix.

packages/admin-ui/src/lib/core/src/common/base-detail.component.ts (1)

153-161: Propagating owner context into custom-field permission checks is correct

Passing isOwner through to permissionsService.userHasPermissions() fixes the visibility issue for Administrator profile custom fields gated by Owner. Defaulting to false keeps other usages unchanged.

packages/admin-ui/src/lib/settings/src/components/profile/profile.component.ts (1)

49-56: Passing isOwner=true for Administrator custom fields fixes the reported bug

This ensures fields requiring Owner appear on the user's own profile while leaving other contexts unaffected.

Comment on lines +153 to +156
protected getCustomFieldConfig(
key: Exclude<keyof CustomFields, '__typename'>,
isOwner = false,
): CustomFieldConfig[] {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function gets called for basically all detail components, so changing the function signature for one single case makes me think twice. I only looked at it briefly so I dont have a better solution right now and you might be totally right, but I think having a closer look at the root cause might be worth it.

In any way, thanks for making a PR!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right that this is just for one case but I couldn't find any other way the admin-ui knows what entities "belong" to the active user. I think this is the most straightforward solution without implementing that belonging logic in the admin-ui that I could think of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants