Skip to content

[SK-2671] feat(roles): add update_default_roles and list_dependent_roles#135

Merged
hrishikesh-p merged 7 commits intomainfrom
fix/sdk-method/rolesservice-update-default-roles-list-dependent
Mar 24, 2026
Merged

[SK-2671] feat(roles): add update_default_roles and list_dependent_roles#135
hrishikesh-p merged 7 commits intomainfrom
fix/sdk-method/rolesservice-update-default-roles-list-dependent

Conversation

@hrishikesh-p
Copy link
Copy Markdown
Contributor

@hrishikesh-p hrishikesh-p commented Mar 16, 2026

Summary

  • Adds update_default_roles(default_creator_role, default_member_role) — sets environment-level default roles (PATCH /api/v1/roles:set_defaults)
  • Adds list_dependent_roles(role_name) — lists roles that inherit from a base role (GET /api/v1/roles/{role_name}/dependents)
  • Adds integration tests in tests/test_role_defaults_dependent.py

Notion: (SK-2671)

Test plan

  • update_default_roles() — accepts no params
  • update_default_roles(default_member_role="member") — sets member role
  • list_dependent_roles("member") — returns response
  • list_dependent_roles("admin") — returns response

Summary by CodeRabbit

  • New Features

    • Update default creator/member roles and list dependent roles.
    • Retrieve a user's assigned roles and permissions within an organization.
  • Tests

    • Added end-to-end tests covering updating default roles, listing dependent roles, and listing user roles/permissions with setup/teardown and response assertions.

@notion-workspace
Copy link
Copy Markdown

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a24a0188-d0ec-4651-b1cc-1961423eb04c

📥 Commits

Reviewing files that changed from the base of the PR and between 3411c64 and 7a1b9d7.

📒 Files selected for processing (1)
  • tests/test_role_defaults_dependent.py
✅ Files skipped from review due to trivial changes (1)
  • tests/test_role_defaults_dependent.py

Walkthrough

Adds RoleClient methods to update default roles and list dependent roles, and UserClient methods to list a user's roles and permissions; includes new integration tests exercising these APIs and small import/whitespace adjustments.

Changes

Cohort / File(s) Summary
Role Management
scalekit/role.py, tests/test_role_defaults_dependent.py
Added RoleClient.update_default_roles(default_creator_role: Optional[str]=None, default_member_role: Optional[str]=None) which constructs UpdateDefaultRolesRequest conditionally setting fields and calls UpdateDefaultRoles via core_client.grpc_exec; added RoleClient.list_dependent_roles(role_name: str) calling ListDependentRoles. Added tests for default-role updates and dependent-role listings.
User Access Queries
scalekit/users.py, tests/test_user_roles_permissions.py
Replaced wildcard imports with explicit protobuf message imports; added UserClient.list_user_roles(organization_id: str, user_id: str) and UserClient.list_user_permissions(organization_id: str, user_id: str) that build respective requests and call RPCs via core_client.grpc_exec. Added tests that create/cleanup org and user and assert list responses.
Formatting / Imports
scalekit/role.py, scalekit/users.py
Minor whitespace/signature formatting change in delete_organization_role_base signature and replaced wildcard import in users.py with explicit message imports (no behavioral changes).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as UserClient/RoleClient
  participant Core as CoreClient.grpc_exec
  participant Service as gRPC Service
  participant Backend as Backend Store

  Client->>Core: build Request (UpdateDefaultRolesRequest / ListDependentRolesRequest / ListUserRolesRequest / ListUserPermissionsRequest)
  Core->>Service: invoke RPC (UpdateDefaultRoles / ListDependentRoles / ListUserRoles / ListUserPermissions)
  Service->>Backend: read/update role & permission data
  Backend-->>Service: return payload
  Service-->>Core: RPC response
  Core-->>Client: parsed Response object
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 I hopped through requests and crafted a few,
Default roles set, dependents listed too,
Users’ roles and perms now spring to light,
Tests hop in place to prove they're right,
🥕 a tiny rabbit’s celebratory chew.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main changes: adding two new role service methods (update_default_roles and list_dependent_roles) to the SDK.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sdk-method/rolesservice-update-default-roles-list-dependent

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

Copy link
Copy Markdown

@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: 2

🧹 Nitpick comments (1)
scalekit/role.py (1)

372-375: Use explicit None checks when populating optional request fields.

At Line 372 and Line 374, truthiness checks make empty-string input a silent no-op. Prefer is not None so behavior is explicit.

Suggested patch
-        if default_creator_role:
+        if default_creator_role is not None:
             req.default_creator_role = default_creator_role
-        if default_member_role:
+        if default_member_role is not None:
             req.default_member_role = default_member_role
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scalekit/role.py` around lines 372 - 375, The checks that populate
req.default_creator_role and req.default_member_role currently use truthiness
(if default_creator_role / if default_member_role) which silently skips
empty-string values; update these to explicit None checks (if
default_creator_role is not None / if default_member_role is not None) in
scalekit/role.py so empty strings are treated as valid values while still
skipping absent (None) inputs—locate the assignment sites referencing
req.default_creator_role and req.default_member_role and replace the conditional
expressions accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scalekit/users.py`:
- Around line 395-433: Add explicit imports for the four protobuf symbols Ruff
flags as undefined: ListUserPermissionsRequest, ListUserPermissionsResponse,
ListUserRolesRequest, and ListUserRolesResponse from
scalekit.v1.users.users_pb2; these symbols are referenced in the methods
list_user_permissions and list_user_roles (and their use of
core_client.grpc_exec and user_service.ListUserPermissions.with_call /
ListUserRoles.with_call), so replace the star import by adding those four names
to the module imports to satisfy the linter.

In `@tests/test_role_defaults_dependent.py`:
- Around line 15-21: The test test_update_default_roles_with_member_role mutates
global environment state by calling
role.update_default_roles(default_member_role="member") without restoring the
previous default; modify the test to read and save the existing
default_member_role via role.get_default_roles (or the existing API that returns
current defaults) before calling update_default_roles, then restore the saved
value after the assertion—either using a try/finally block or self.addCleanup to
call role.update_default_roles with the original value—so the environment
default is always reverted even on test failure.

---

Nitpick comments:
In `@scalekit/role.py`:
- Around line 372-375: The checks that populate req.default_creator_role and
req.default_member_role currently use truthiness (if default_creator_role / if
default_member_role) which silently skips empty-string values; update these to
explicit None checks (if default_creator_role is not None / if
default_member_role is not None) in scalekit/role.py so empty strings are
treated as valid values while still skipping absent (None) inputs—locate the
assignment sites referencing req.default_creator_role and
req.default_member_role and replace the conditional expressions accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91dfc5d8-b5fd-4fdc-9446-ee7f3759f835

📥 Commits

Reviewing files that changed from the base of the PR and between 701ea15 and 76c156b.

📒 Files selected for processing (4)
  • scalekit/role.py
  • scalekit/users.py
  • tests/test_role_defaults_dependent.py
  • tests/test_user_roles_permissions.py

@hrishikesh-p
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 16, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@hrishikesh-p hrishikesh-p changed the title feat(roles): add update_default_roles and list_dependent_roles (SK-2671) [SK-2671] feat(roles): add update_default_roles and list_dependent_roles Mar 17, 2026
- role.py: use 'is not None' instead of truthiness for default_creator_role
  and default_member_role to allow empty-string values through explicitly
- users.py: replace star import with explicit named imports for all pb2
  symbols used in the module (Ruff F401/F403)
- test_role_defaults_dependent.py: add addCleanup to restore default_member_role
  after test_update_default_roles_with_member_role to avoid mutating global
  environment state
Copy link
Copy Markdown

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

🧹 Nitpick comments (1)
scalekit/role.py (1)

355-394: Resolve F405 linting by adding explicit imports for protobuf symbols.

Ruff's F405 rule flags undefined names from wildcard imports. Add explicit imports for the four protobuf symbols used in this file:

Import fix
 from scalekit.core import CoreClient
 from scalekit.v1.roles.roles_pb2 import *
+from scalekit.v1.roles.roles_pb2 import (
+    ListDependentRolesRequest,
+    ListDependentRolesResponse,
+    UpdateDefaultRolesRequest,
+    UpdateDefaultRolesResponse,
+)
 from scalekit.v1.roles.roles_pb2_grpc import RolesServiceStub
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scalekit/role.py` around lines 355 - 394, The file is triggering F405 due to
wildcard imports for protobuf symbols used in update_default_roles and
list_dependent_roles; add explicit imports for UpdateDefaultRolesRequest,
UpdateDefaultRolesResponse, ListDependentRolesRequest, and
ListDependentRolesResponse from the generated protobuf module (rather than using
a star import) so the names referenced in update_default_roles,
list_dependent_roles, and the role_service.grpc calls are defined; update the
import statement at the top of the module to import those four symbols
explicitly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@scalekit/role.py`:
- Around line 355-394: The file is triggering F405 due to wildcard imports for
protobuf symbols used in update_default_roles and list_dependent_roles; add
explicit imports for UpdateDefaultRolesRequest, UpdateDefaultRolesResponse,
ListDependentRolesRequest, and ListDependentRolesResponse from the generated
protobuf module (rather than using a star import) so the names referenced in
update_default_roles, list_dependent_roles, and the role_service.grpc calls are
defined; update the import statement at the top of the module to import those
four symbols explicitly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 79f2becf-b69c-4d15-b576-f5e408ecac02

📥 Commits

Reviewing files that changed from the base of the PR and between 76c156b and 38d3cb8.

📒 Files selected for processing (3)
  • scalekit/role.py
  • scalekit/users.py
  • tests/test_role_defaults_dependent.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • scalekit/users.py
  • tests/test_role_defaults_dependent.py

ScalekitClient exposes the RoleClient as self.roles (plural), not
self.role. Tests were referencing the non-existent .role attribute,
causing AttributeError in CI.
@hrishikesh-p hrishikesh-p merged commit ac9d3de into main Mar 24, 2026
1 of 2 checks passed
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