Skip to content
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

add_policies only updates policies, but not policy_map #356

Open
derberni opened this issue Oct 8, 2024 · 4 comments
Open

add_policies only updates policies, but not policy_map #356

derberni opened this issue Oct 8, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@derberni
Copy link

derberni commented Oct 8, 2024

If you compare the two functions for adding a single, or multiple policies in model/policy.py, the add_policies method only appends the new rules, but does not update the policy_map if a priority is given for the rule.

@casbin-bot
Copy link
Member

@techoner @Nekotoxin

@casbin-bot casbin-bot added the enhancement New feature or request label Oct 8, 2024
@hsluoyz
Copy link
Member

hsluoyz commented Oct 8, 2024

@derberni try other languages like Go, Java, Node Casbin

@derberni
Copy link
Author

I checked the Go source code for AddPolicies, and it works correctly. Basically the Go AddPolicies calls AddPolicy for each policy. The python code for add_policies does not use add_policy internally, but directly appends the policy list to the model.

@hsluoyz
Copy link
Member

hsluoyz commented Oct 13, 2024

Task: need to port the policy_map handling from Go to Python. See the below links.

Note: consider not only add_policies but also other similar functions like: update_policies, remove_policies, etc. in the same source code file

Go:

https://github.com/casbin/casbin/blob/c55ed50772950c9b6eb80460fed5b889e0df87fd/model/policy.go#L259-L279

Python:

def add_policies(self, sec, ptype, rules):
"""adds policy rules to the model."""
for rule in rules:
if self.has_policy(sec, ptype, rule):
return False
for rule in rules:
self[sec][ptype].policy.append(rule)
return True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants