feat: add methods to retrieve domains for users and roles - #524
Conversation
|
|
Pull Request Test Coverage Report for Build 20033979759Details
💛 - Coveralls |
Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
|
@copilot should exactly use the same behavior as Go Casbin, including code and test cases and naming patterns |
- Add getDomains and getAllDomains methods to RoleManager interface - Implement methods in DefaultRoleManager following Go pattern - Update Enforcer to call RoleManager methods (not ManagementEnforcer) - Add rbac_with_domains_policy2.csv test file matching Go Casbin - Update tests to match Go Casbin test patterns and naming - Filter out default domain when other domains exist Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
- Update getDomainsForUser comment to be more descriptive - Improve getDomains logic to check both roles and users - Rename helper method for clarity (hasUserForRole) - All tests pass Co-authored-by: mserico <140243407+mserico@users.noreply.github.com>
Updated to match Go Casbin exactly: ✅ Added All 186 tests pass. See commit 2ba42d1 for the final implementation. |
Users need to retrieve all domains associated with a user or role without manually iterating through policies. The Go Casbin library has
getDomainfunctionality, but node-casbin lacked equivalent methods.This implementation follows the exact Go Casbin pattern, architecture, and test cases to ensure compatibility.
Changes
RoleManager Interface - Added methods matching Go Casbin:
getDomains(name: string): Gets domains that a user hasgetAllDomains(): Gets all domainsDefaultRoleManager - Implemented RoleManager methods:
Enforcer - Added user-facing RBAC methods:
getDomainsForUser(user): Returns all domains for a user by calling RoleManagergetAllDomains(): Returns all domains by calling RoleManagerTest Coverage
rbac_with_domains_policy2.csvmatching Go Casbin test dataUsage
Policy example:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.