Skip to content

feat: add policy management for permission-binding junctions - #2992

Merged
tada5hi merged 4 commits into
masterfrom
2987-policy-assignment
Apr 16, 2026
Merged

tada5hi merged 4 commits into
masterfrom
2987-policy-assignment

Conversation

@tada5hi

@tada5hi tada5hi commented Apr 15, 2026 •

Copy link
Copy Markdown
Collaborator

closes #2987

Summary by CodeRabbit

  • New Features
    • Added ability to update and edit permission configurations for client, robot, role, and user permissions.
    • Added new policy binding functionality allowing users to select and assign junction policies to permission relations through an intuitive interface.

Copilot AI review requested due to automatic review settings April 15, 2026 16:15
@coderabbitai

coderabbitai Bot commented Apr 15, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@tada5hi has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 49 minutes and 41 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 49 minutes and 41 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 996321e0-c0bb-41d2-879c-7c77a25bb731

📥 Commits

Reviewing files that changed from the base of the PR and between 8026a89 and 87b0c64.

📒 Files selected for processing (8)
  • packages/client-web-kit/src/components/entities/client-permission/AClientPermissionAssignment.ts
  • packages/client-web-kit/src/components/entities/index.ts
  • packages/client-web-kit/src/components/entities/permission-policy-binding/APermissionPolicyBindingButton.ts
  • packages/client-web-kit/src/components/entities/permission-policy-binding/index.ts
  • packages/client-web-kit/src/components/entities/robot-permission/ARobotPermissionAssignment.ts
  • packages/client-web-kit/src/components/entities/role-permission/ARolePermissionAssignment.ts
  • packages/client-web-kit/src/components/entities/user-permission/AUserPermissionAssignment.ts
  • packages/client-web-kit/src/components/utility/entity/collection/utils/handlers.ts
📝 Walkthrough

Walkthrough

The PR adds update functionality for permission-binding junction entities (ClientPermission, RobotPermission, RolePermission, UserPermission) across the backend and frontend. New HTTP POST endpoints enable modifying the policy_id field on these permissions with proper authorization checks. A new Vue modal component provides UI for selecting or clearing the junction policy. Assignment components are updated to render the policy button alongside existing toggle controls.

Changes

Cohort / File(s) Summary
Backend: HTTP Controllers
apps/server-core/src/adapters/http/controllers/entities/client-permission/module.ts, robot-permission/module.ts, role-permission/module.ts, user-permission/module.ts
Added new POST /:id edit endpoints with ForceLoggedInMiddleware. Each extracts id from path, builds actor context, calls service update(id, data, actor), and returns result via sendAccepted.
Backend: Service Implementation
apps/server-core/src/core/entities/client-permission/service.ts, robot-permission/service.ts, role-permission/service.ts, user-permission/service.ts
Added update(id, data, actor) method to each service. Method performs permission preEvaluate, loads entity by id, extracts policy_id from data, validates join columns, merges changes, evaluates permission on merged entity, and persists via repository.
Backend: Service Interfaces
apps/server-core/src/core/entities/client-permission/types.ts, robot-permission/types.ts, role-permission/types.ts, user-permission/types.ts
Added update(id: string, data: Record<string, any>, actor: ActorContext): Promise<Entity> method signature to each service interface.
Backend: Unit Tests
apps/server-core/test/unit/core/entities/client-permission/service.spec.ts, robot-permission/service.spec.ts, role-permission/service.spec.ts, user-permission/service.spec.ts
Added describe('update') test suites covering: updating policy_id, clearing policy_id, rejecting non-existent entities, authorization via preEvaluate, forbidding unauthorized updates, and ensuring only policy_id changes.
Backend: Permission Constants
packages/core-kit/src/domains/permission/constants.ts
Added four new enum members to PermissionName: CLIENT_PERMISSION_UPDATE, ROBOT_PERMISSION_UPDATE, ROLE_PERMISSION_UPDATE, USER_PERMISSION_UPDATE.
HTTP API Clients
packages/core-http-kit/src/domains/entities/client-permission/module.ts, robot-permission/module.ts, role-permission/module.ts, user-permission/module.ts
Updated each API class from EntityAPISlim<T> to EntityAPI<T>. Added update(id: T['id'], data: Partial<T>): Promise<EntityRecordResponse<T>> method issuing POST {entity}/{id} with data payload.
Frontend: Policy Button Component
packages/client-web-kit/src/components/entities/permission-binding-policy/APermissionBindingPolicyButton.ts, permission-binding-policy/index.ts, entities/index.ts
Added new APermissionBindingPolicyButton modal component for selecting/clearing junction policy. Tracks modalOpen, busy, currentPolicyId state. Calls API update() on policy selection, emits updated/failed, closes modal after success. New directory exported via module indices.
Frontend: Assignment Components
packages/client-web-kit/src/components/entities/client-permission/AClientPermissionAssignment.ts, robot-permission/ARobotPermissionAssignment.ts, role-permission/ARolePermissionAssignment.ts, user-permission/AUserPermissionAssignment.ts
Updated render to wrap toggle button in h('span') container. Added conditional APermissionBindingPolicyButton sibling (appears when manager.data.value exists) with entityType, entity, and onUpdated handler passing updates back to manager.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 A gear icon appears, oh what a sight,
Four permissions dance in authorization's light,
Modal pops, policy picked with care,
Junction bindings get their policy share!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add policy management for permission-binding junctions' accurately summarizes the main change: adding UI and API support to manage junction-level policies for permission-binding entities.
Linked Issues check ✅ Passed All coding requirements from issue #2987 are met: backend update methods for all four permission entities [ClientPermission, RobotPermission, RolePermission, UserPermission], proper authorization checks, frontend components integrating policy selection modal, and permission binding updates.
Out of Scope Changes check ✅ Passed All changes are directly aligned with issue #2987 objectives. No unrelated modifications were detected; all additions target policy management for permission-binding junctions across the specified four entity types.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2987-policy-assignment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds end-to-end support for managing junction-level policies (policy_id) on permission-binding entities (role/user/client/robot-permission), enabling the UI to assign/clear a single policy per binding and the server/API to persist those changes.

Changes:

  • Introduces new *_PERMISSION_UPDATE permission names and adds server-side update() support (service + controller) to update only policy_id.
  • Extends core-http-kit junction APIs with update() and switches to EntityAPI where needed.
  • Updates assignment UI components to show a new policy-management button + modal for assigned bindings, and adds unit tests for update behavior.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/core-kit/src/domains/permission/constants.ts Adds *_PERMISSION_UPDATE permission names for junction policy updates.
packages/core-http-kit/src/domains/entities/user-permission/module.ts Adds update() to UserPermissionAPI and implements EntityAPI.
packages/core-http-kit/src/domains/entities/role-permission/module.ts Adds update() to RolePermissionAPI and implements EntityAPI.
packages/core-http-kit/src/domains/entities/robot-permission/module.ts Adds update() to RobotPermissionAPI and implements EntityAPI.
packages/core-http-kit/src/domains/entities/client-permission/module.ts Adds update() to ClientPermissionAPI and implements EntityAPI.
packages/client-web-kit/src/components/entities/user-permission/AUserPermissionAssignment.ts Renders policy button + modal entry point when binding exists.
packages/client-web-kit/src/components/entities/role-permission/ARolePermissionAssignment.ts Renders policy button + modal entry point when binding exists.
packages/client-web-kit/src/components/entities/robot-permission/ARobotPermissionAssignment.ts Renders policy button + modal entry point when binding exists.
packages/client-web-kit/src/components/entities/client-permission/AClientPermissionAssignment.ts Renders policy button + modal entry point when binding exists.
packages/client-web-kit/src/components/entities/permission-binding-policy/index.ts Exports new policy-management button component.
packages/client-web-kit/src/components/entities/permission-binding-policy/APermissionBindingPolicyButton.ts Implements modal UI to set/clear policy_id via api.update().
packages/client-web-kit/src/components/entities/index.ts Exposes permission-binding-policy components via entities barrel export.
apps/server-core/test/unit/core/entities/user-permission/service.spec.ts Adds unit tests for update() policy_id behavior and authorization.
apps/server-core/test/unit/core/entities/role-permission/service.spec.ts Adds unit tests for update() policy_id behavior and authorization.
apps/server-core/test/unit/core/entities/robot-permission/service.spec.ts Adds unit tests for update() policy_id behavior and authorization.
apps/server-core/test/unit/core/entities/client-permission/service.spec.ts Adds unit tests for update() policy_id behavior and authorization.
apps/server-core/src/core/entities/user-permission/types.ts Adds update() to IUserPermissionService.
apps/server-core/src/core/entities/user-permission/service.ts Implements update() to change only policy_id.
apps/server-core/src/core/entities/role-permission/types.ts Adds update() to IRolePermissionService.
apps/server-core/src/core/entities/role-permission/service.ts Implements update() to change only policy_id.
apps/server-core/src/core/entities/robot-permission/types.ts Adds update() to IRobotPermissionService.
apps/server-core/src/core/entities/robot-permission/service.ts Implements update() to change only policy_id.
apps/server-core/src/core/entities/client-permission/types.ts Adds update() to IClientPermissionService.
apps/server-core/src/core/entities/client-permission/service.ts Implements update() to change only policy_id.
apps/server-core/src/adapters/http/controllers/entities/user-permission/module.ts Adds POST /user-permissions/:id edit endpoint calling service.update().
apps/server-core/src/adapters/http/controllers/entities/role-permission/module.ts Adds POST /role-permissions/:id edit endpoint calling service.update().
apps/server-core/src/adapters/http/controllers/entities/robot-permission/module.ts Adds POST /robot-permissions/:id edit endpoint calling service.update().
apps/server-core/src/adapters/http/controllers/entities/client-permission/module.ts Adds POST /client-permissions/:id edit endpoint calling service.update().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@packages/client-web-kit/src/components/entities/permission-binding-policy/APermissionBindingPolicyButton.ts`:
- Around line 94-107: The settings button rendered in
APermissionBindingPolicyButton is icon-only and lacks an accessible name; update
the h('button', ...) call to include an accessible label (e.g., add
aria-label="Open policy settings" or a descriptive title) and mark the icon
element as decorative (set the <i> element's props to { 'aria-hidden': 'true' })
so screen readers get the button label only; ensure you update the button props
object (where class, disabled, onClick are defined) to include the
aria-label/title and adjust the h('i', ...) props accordingly.
- Around line 80-83: The catch in APermissionBindingPolicyButton currently
ignores throwables that are not instances of Error; change the handler so it
always emits a failure Error: inside the catch replace the conditional with code
that creates an Error when e is not an Error (e.g. const err = e instanceof
Error ? e : new Error(String(e)); and, if supported, attach the original value
as a property or cause), then call emit('failed', err); this ensures
emit('failed', ...) is always called for any thrown value in the
APermissionBindingPolicyButton catch block.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5b58ee0b-5ed5-4dde-b181-eef3ba224f5e

📥 Commits

Reviewing files that changed from the base of the PR and between 54a6680 and 8026a89.

📒 Files selected for processing (28)
  • apps/server-core/src/adapters/http/controllers/entities/client-permission/module.ts
  • apps/server-core/src/adapters/http/controllers/entities/robot-permission/module.ts
  • apps/server-core/src/adapters/http/controllers/entities/role-permission/module.ts
  • apps/server-core/src/adapters/http/controllers/entities/user-permission/module.ts
  • apps/server-core/src/core/entities/client-permission/service.ts
  • apps/server-core/src/core/entities/client-permission/types.ts
  • apps/server-core/src/core/entities/robot-permission/service.ts
  • apps/server-core/src/core/entities/robot-permission/types.ts
  • apps/server-core/src/core/entities/role-permission/service.ts
  • apps/server-core/src/core/entities/role-permission/types.ts
  • apps/server-core/src/core/entities/user-permission/service.ts
  • apps/server-core/src/core/entities/user-permission/types.ts
  • apps/server-core/test/unit/core/entities/client-permission/service.spec.ts
  • apps/server-core/test/unit/core/entities/robot-permission/service.spec.ts
  • apps/server-core/test/unit/core/entities/role-permission/service.spec.ts
  • apps/server-core/test/unit/core/entities/user-permission/service.spec.ts
  • packages/client-web-kit/src/components/entities/client-permission/AClientPermissionAssignment.ts
  • packages/client-web-kit/src/components/entities/index.ts
  • packages/client-web-kit/src/components/entities/permission-binding-policy/APermissionBindingPolicyButton.ts
  • packages/client-web-kit/src/components/entities/permission-binding-policy/index.ts
  • packages/client-web-kit/src/components/entities/robot-permission/ARobotPermissionAssignment.ts
  • packages/client-web-kit/src/components/entities/role-permission/ARolePermissionAssignment.ts
  • packages/client-web-kit/src/components/entities/user-permission/AUserPermissionAssignment.ts
  • packages/core-http-kit/src/domains/entities/client-permission/module.ts
  • packages/core-http-kit/src/domains/entities/robot-permission/module.ts
  • packages/core-http-kit/src/domains/entities/role-permission/module.ts
  • packages/core-http-kit/src/domains/entities/user-permission/module.ts
  • packages/core-kit/src/domains/permission/constants.ts

Comment on lines +80 to +83
} catch (e) {
if (e instanceof Error) {
emit('failed', e);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Don’t silently drop non-Error throwables.

At Lines 80-83, thrown values that are not Error are ignored, so failure signals can be lost.

🛠️ Proposed fix
             } catch (e) {
-                if (e instanceof Error) {
-                    emit('failed', e);
-                }
+                emit('failed', e instanceof Error ? e : new Error('Failed to update junction policy.'));
             } finally {
                 busy.value = false;
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (e) {
if (e instanceof Error) {
emit('failed', e);
}
} catch (e) {
emit('failed', e instanceof Error ? e : new Error('Failed to update junction policy.'));
} finally {
busy.value = false;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/client-web-kit/src/components/entities/permission-binding-policy/APermissionBindingPolicyButton.ts`
around lines 80 - 83, The catch in APermissionBindingPolicyButton currently
ignores throwables that are not instances of Error; change the handler so it
always emits a failure Error: inside the catch replace the conditional with code
that creates an Error when e is not an Error (e.g. const err = e instanceof
Error ? e : new Error(String(e)); and, if supported, attach the original value
as a property or cause), then call emit('failed', err); this ensures
emit('failed', ...) is always called for any thrown value in the
APermissionBindingPolicyButton catch block.

Comment on lines +94 to +107
children.push(h('button', {
class: ['btn btn-xs', {
'btn-dark': busy.value,
'btn-primary': !busy.value && currentPolicyId.value,
'btn-secondary': !busy.value && !currentPolicyId.value,
}],
disabled: busy.value,
onClick(e: Event) {
e.preventDefault();
modalOpen.value = true;
},
}, [
h('i', { class: 'fa fa-cog' }),
]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add an accessible name to the icon-only settings button.

At Line 94, the trigger is icon-only and has no label for assistive tech.

♿ Proposed fix
             children.push(h('button', {
+                type: 'button',
                 class: ['btn btn-xs', {
                     'btn-dark': busy.value,
                     'btn-primary': !busy.value && currentPolicyId.value,
                     'btn-secondary': !busy.value && !currentPolicyId.value,
                 }],
+                'aria-label': 'Manage junction policy',
+                title: 'Manage junction policy',
                 disabled: busy.value,
                 onClick(e: Event) {
                     e.preventDefault();
                     modalOpen.value = true;
                 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
children.push(h('button', {
class: ['btn btn-xs', {
'btn-dark': busy.value,
'btn-primary': !busy.value && currentPolicyId.value,
'btn-secondary': !busy.value && !currentPolicyId.value,
}],
disabled: busy.value,
onClick(e: Event) {
e.preventDefault();
modalOpen.value = true;
},
}, [
h('i', { class: 'fa fa-cog' }),
]));
children.push(h('button', {
type: 'button',
class: ['btn btn-xs', {
'btn-dark': busy.value,
'btn-primary': !busy.value && currentPolicyId.value,
'btn-secondary': !busy.value && !currentPolicyId.value,
}],
'aria-label': 'Manage junction policy',
title: 'Manage junction policy',
disabled: busy.value,
onClick(e: Event) {
e.preventDefault();
modalOpen.value = true;
},
}, [
h('i', { class: 'fa fa-cog' }),
]));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/client-web-kit/src/components/entities/permission-binding-policy/APermissionBindingPolicyButton.ts`
around lines 94 - 107, The settings button rendered in
APermissionBindingPolicyButton is icon-only and lacks an accessible name; update
the h('button', ...) call to include an accessible label (e.g., add
aria-label="Open policy settings" or a descriptive title) and mark the icon
element as decorative (set the <i> element's props to { 'aria-hidden': 'true' })
so screen readers get the button label only; ensure you update the button props
object (where class, disabled, onClick are defined) to include the
aria-label/title and adjust the h('i', ...) props accordingly.

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.

Add policy management for permission-binding junctions (role/user/client/robot-permission)

2 participants