Skip to content

Commit

Permalink
feat: add watcher-ex call (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotoxin authored Aug 8, 2022
1 parent e910042 commit f4bc0c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion casbin/core_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ def save_policy(self):
self.adapter.save_policy(self.model)

if self.watcher:
self.watcher.update()
if callable(getattr(self.watcher, "update_for_save_policy", None)):
self.watcher.update_for_save_policy(self.model)
else:
self.watcher.update()

def enable_enforce(self, enabled=True):
"""changes the enforcing state of Casbin,
Expand Down
25 changes: 20 additions & 5 deletions casbin/internal_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ def _add_policy(self, sec, ptype, rule):
return False

if self.watcher:
self.watcher.update()
if callable(getattr(self.watcher, "update_for_add_policy", None)):
self.watcher.update_for_add_policy(sec, ptype, rule)
else:
self.watcher.update()

return rule_added

Expand All @@ -50,7 +53,10 @@ def _add_policies(self, sec, ptype, rules):
return False

if self.watcher:
self.watcher.update()
if callable(getattr(self.watcher, "update_for_add_policies", None)):
self.watcher.update_for_add_policies(sec, ptype, rules)
else:
self.watcher.update()

return rules_added

Expand Down Expand Up @@ -124,7 +130,10 @@ def _remove_policy(self, sec, ptype, rule):
return False

if self.watcher:
self.watcher.update()
if callable(getattr(self.watcher, "update_for_remove_policy", None)):
self.watcher.update_for_remove_policy(sec, ptype, rule)
else:
self.watcher.update()

return rule_removed

Expand All @@ -142,7 +151,10 @@ def _remove_policies(self, sec, ptype, rules):
return False

if self.watcher:
self.watcher.update()
if callable(getattr(self.watcher, "update_for_remove_policies", None)):
self.watcher.update_for_remove_policies(sec, ptype, rules)
else:
self.watcher.update()

return rules_removed

Expand All @@ -157,7 +169,10 @@ def _remove_filtered_policy(self, sec, ptype, field_index, *field_values):
return False

if self.watcher:
self.watcher.update()
if callable(getattr(self.watcher, "update_for_remove_filtered_policy", None)):
self.watcher.update_for_remove_filtered_policy(sec, ptype, field_index, *field_values)
else:
self.watcher.update()

return rule_removed

Expand Down

0 comments on commit f4bc0c0

Please sign in to comment.