-
-
Notifications
You must be signed in to change notification settings - Fork 227
feat: implement self* methods using WithoutNotify pattern (sync with Go) #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement self* methods using WithoutNotify pattern (sync with Go) #539
Conversation
Pull Request Test Coverage Report for Build 20877464519Details
💛 - Coveralls |
c64e7a6 to
289e9fb
Compare
289e9fb to
afa3426
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the self* methods in the Management API to use a new *WithoutNotify pattern, aligning with the Go Casbin implementation. The refactoring prevents infinite loops in distributed environments by ensuring that self-operations bypass both adapter persistence and watcher notifications, operating strictly on the in-memory model.
Changes:
- Introduced new
*WithoutNotifyprotected methods inInternalEnforcerthat update only the in-memory model - Refactored all
self*methods inManagementEnforcerto delegate to the corresponding*WithoutNotifymethods - Added comprehensive test coverage to verify self-operations bypass adapters while correctly updating memory
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/managementAPI_self.test.ts | New comprehensive test suite validating that self* methods bypass adapters and update memory correctly, including edge cases |
| src/managementEnforcer.ts | Refactored all self* methods to call *WithoutNotify variants; added selfUpdatePolicies method; updated selfRemoveFilteredPolicy signature to use rest parameters |
| src/internalEnforcer.ts | Added six new *WithoutNotify protected methods that update the model without calling adapters or watchers; added comments clarifying when persistence occurs in existing methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add *WithoutNotify internal methods that skip adapter and watcher - Implement selfAddPolicy, selfRemovePolicy, selfUpdatePolicy, selfAddPolicies, selfRemovePolicies, selfRemoveFilteredPolicy, selfUpdatePolicies - These methods only update in-memory model to prevent infinite loops in distributed watcher scenarios - Add comprehensive unit tests with edge cases and grouping policy coverage - Align with Go Casbin implementation pattern Fixes casbin#506
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
🎉 This PR is included in version 5.48.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
This PR refactors the implementation to match the Go Casbin approach, as requested by the maintainer.
It introduces
*WithoutNotifyinternal methods that operate strictly on the memory model (bypassing both adapter and watcher) and updatesself*methods to call them directly. This prevents infinite loops in distributed environments.Related Issue
Fixes #506
Verification
selfAddPolicyupdates memory correctly without invokingadapter.addPolicy.