Skip to content

Commit

Permalink
feat: update_filtered_policies
Browse files Browse the repository at this point in the history
  • Loading branch information
Shivansh-yadav13 committed Apr 7, 2022
1 parent 725715f commit 84e2139
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions casbin/internal_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ def _update_policies(self, sec, ptype, old_rules, new_rules):

return rules_updated

def _update_filtered_policies(
self, sec, ptype, new_rules, field_index, *field_values
):
"""updates rules from currect policy on the basis of filter"""

if self.adapter and self.auto_save:

if (
self.adapter.update_filtered_policies(
sec, ptype, new_rules, field_index, *field_values
)
is False
):
return False

if self.watcher:
self.watcher.update()

return True

return False

def _remove_policy(self, sec, ptype, rule):
"""removes a rule from the current policy."""
rule_removed = self.model.remove_policy(sec, ptype, rule)
Expand Down
14 changes: 14 additions & 0 deletions casbin/management_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,20 @@ def update_named_policies(self, ptype, old_rules, new_rules):
"""updates authorization rules from the current named policy."""
return self._update_policies("p", ptype, old_rules, new_rules)

def update_filtered_policies(self, new_rules, field_index, *field_values):
"""updates all the filtered authorization rules to new rules."""
return self.update_filtered_named_policies(
"p", new_rules, field_index, *field_values
)

def update_filtered_named_policies(
self, ptype, new_rules, field_index, *field_values
):
"""updates all the filtered authorization rules to new rules."""
return self._update_filtered_policies(
"p", ptype, new_rules, field_index, *field_values
)

def remove_policy(self, *params):
"""removes an authorization rule from the current policy."""
return self.remove_named_policy("p", *params)
Expand Down

0 comments on commit 84e2139

Please sign in to comment.