diff --git a/casbin/core_enforcer.py b/casbin/core_enforcer.py index 5f401eb3..a4280678 100644 --- a/casbin/core_enforcer.py +++ b/casbin/core_enforcer.py @@ -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, diff --git a/casbin/internal_enforcer.py b/casbin/internal_enforcer.py index 48e49362..fb63b5d2 100644 --- a/casbin/internal_enforcer.py +++ b/casbin/internal_enforcer.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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