-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(admin-ui): Administrator's customField don't show up in profile if requiresPermission is Owner #3757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…f requiresPermission is Owner
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughIntroduces 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
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[]
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this 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 readersA short TSDoc will make the OR semantics and the special-case for
Permission.Ownerexplicit.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 docsGiven this method is used broadly by detail components, documenting when to pass
isOwnerwill 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.
📒 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-compatibleAdding the
isOwnerflag and short-circuiting whenPermission.Owneris present addresses the visibility bug without impacting existing call sites (defaultfalse). 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 correctPassing
isOwnerthrough topermissionsService.userHasPermissions()fixes the visibility issue for Administrator profile custom fields gated byOwner. Defaulting tofalsekeeps 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 bugThis ensures fields requiring
Ownerappear on the user's own profile while leaving other contexts unaffected.
| protected getCustomFieldConfig( | ||
| key: Exclude<keyof CustomFields, '__typename'>, | ||
| isOwner = false, | ||
| ): CustomFieldConfig[] { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.



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:
👍 Most of the time:
Summary by CodeRabbit