fix(policy): update policy_map by calling add_policy #377
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.
This Pull Request fixes the issue where add_policies does not update the internal policy_map when adding new policies (see #356). Previously, add_policies simply appended new rules to the policy list without invoking add_policy, causing priority and other related information to be missing from policy_map. The main changes include:
Invoke add_policy for Each Rule
In add_policies, each new rule is added via the add_policy method to ensure that both the policy list and the policy_map are updated.
This approach is aligned with the Go Casbin implementation for consistency.
Duplicate Check
If any rule already exists, the function returns False to prevent adding duplicates.
Testing
All existing test cases have been run locally, and they pass successfully.
Additional tests for priority-based rules can be added in the future to further confirm that policy_map is correctly updated.
By applying this fix, add_policies now properly maintains the internal data structures, preventing access control logic errors due to an out-of-sync policy_map. Feedback and reviews are welcome!