Fix setPermission() to support enforcer format from Go backend's CasbinJsGetPermissionForUser#285
Open
Fix setPermission() to support enforcer format from Go backend's CasbinJsGetPermissionForUser#285
Conversation
|
|
- Made setPermission() async to support both simple and enforcer formats - Auto-detect enforcer format (with 'm' and 'p' keys) and use initEnforcer() - Update can() to check for enforcer in manual mode - Update setUser() to set user in all modes (needed for enforcer in manual mode) - Add comprehensive tests for new functionality - Update README with examples of both formats Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix CasbinJsGetPermissionForUser export issue
Fix setPermission() to support enforcer format from Go backend's CasbinJsGetPermissionForUser
Oct 11, 2025
Member
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.
Problem
Users integrating casbin.js with Go backends using
CasbinJsGetPermissionForUserwere unable to use manual mode correctly. The Go function exports permissions in an "enforcer format" containing model (m) and policies (p), butsetPermission()only supported a simple action-object format like{"read": ["data1", "data2"], "write": ["data1"]}.This caused permission checks to return
falsewhen they should returntrue:Solution
Enhanced
setPermission()to automatically detect and handle both permission formats:m(model) orp(policies) keys to identify enforcer formatinitEnforcer()for enforcer format, orPermission.load()for simple formatcan()method now checks if an enforcer is available in manual modesetUser()now sets the user property in all modes (required for enforcer-based permissions)Changes
setPermission()async to support enforcer initializationcan()to check for enforcer in manual mode before falling back to simple permission checksetUser()to work properly in manual mode with enforcer formatUsage
Breaking Change
setPermission()is now async and returnsPromise<void>instead ofvoid. Existing code needs to addawait:Testing
Fixes #[issue_number]
Original prompt
Fixes #284
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.