pycasbin icon indicating copy to clipboard operation
pycasbin copied to clipboard

fix(policy): update policy_map by calling add_policy

Open Victor-Bayim opened this issue 1 year ago • 1 comments

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!

Victor-Bayim avatar Mar 20 '25 15:03 Victor-Bayim

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 20 '25 15:03 CLAassistant

Replaced by: https://github.com/casbin/pycasbin/pull/390

hsluoyz avatar Jul 26 '25 01:07 hsluoyz