feat: add role management helper methods#114
Merged
hsluoyz merged 1 commit intocasdoor:masterfrom Nov 4, 2025
Merged
Conversation
Add convenient methods for managing user role assignments: - assign_role_to_user(username, role_name): Assign a role to a user - remove_role_from_user(username, role_name): Remove a role from a user - get_user_roles(username): Get all roles assigned to a user - get_roles(): Get all roles in the organization - get_role(role_name): Get a specific role - update_role(role): Update a role Both sync and async versions included. These methods simplify the common task of role assignment by handling the workflow of fetching the role, modifying the users list, and updating the role in a single call.
Contributor
Author
|
@hsluoyz this provides an easy solution using the SDK |
github-actions bot
pushed a commit
that referenced
this pull request
Nov 4, 2025
# [1.40.0](v1.39.0...v1.40.0) (2025-11-04) ### Features * add role management helper methods ([#114](#114)) ([f3873e9](f3873e9))
|
🎉 This PR is included in version 1.40.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds helper methods for managing user role assignments through the Casdoor role API, following the workflow described in issue #4360.
Changes
New Methods:
get_roles()- Retrieve all roles in the organizationget_role(role_name)- Retrieve a specific roleupdate_role(role)- Update role configurationassign_role_to_user(username, role_name)- Add user to roleremove_role_from_user(username, role_name)- Remove user from roleget_user_roles(username)- List all roles for a userAll methods available in both sync (
CasdoorSDK) and async (AsyncCasdoorSDK) versions.Implementation
These methods handle role assignment through the proper API workflow:
get-roleendpointusersarrayupdate-roleendpointThis approach correctly manages the extended
rolesfield as outlined in the maintainer response to #4360.Usage Example
Testing
Validated against production Casdoor instance with real role assignments and removals.
Related
Implements the solution discussed in #4360.