From 6f6a2bf6a5cd1a6a63c6b8ba9b304f44096829d5 Mon Sep 17 00:00:00 2001 From: cs1137195420 <1137195420@qq.com> Date: Wed, 11 May 2022 19:38:25 +0800 Subject: [PATCH 1/2] fix issue #250 --- casbin/management_enforcer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/casbin/management_enforcer.py b/casbin/management_enforcer.py index 0112aeb..bbf7bc9 100644 --- a/casbin/management_enforcer.py +++ b/casbin/management_enforcer.py @@ -275,7 +275,7 @@ def remove_named_grouping_policy(self, ptype, *params): rule_removed = self._remove_policy("g", ptype, list(params)) rules.append(list(params)) - if self.auto_build_role_links: + if self.auto_build_role_links and rule_removed: self.model.build_incremental_role_links(self.rm_map[ptype], PolicyOp.Policy_remove, "g", ptype, rules) return rule_removed From 8d05ef039a371dee5db44d4467f115ef1d4f569f Mon Sep 17 00:00:00 2001 From: cs1137195420 <1137195420@qq.com> Date: Wed, 11 May 2022 19:38:25 +0800 Subject: [PATCH 2/2] fix issue #250 --- casbin/management_enforcer.py | 6 +++--- casbin/rbac/default_role_manager/role_manager.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/casbin/management_enforcer.py b/casbin/management_enforcer.py index 0112aeb..12480d7 100644 --- a/casbin/management_enforcer.py +++ b/casbin/management_enforcer.py @@ -275,7 +275,7 @@ def remove_named_grouping_policy(self, ptype, *params): rule_removed = self._remove_policy("g", ptype, list(params)) rules.append(list(params)) - if self.auto_build_role_links: + if self.auto_build_role_links and rule_removed: self.model.build_incremental_role_links(self.rm_map[ptype], PolicyOp.Policy_remove, "g", ptype, rules) return rule_removed @@ -283,7 +283,7 @@ def remove_named_grouping_policies(self, ptype, rules): """removes role inheritance rules from the current named policy.""" rules_removed = self._remove_policies("g", ptype, rules) - if self.auto_build_role_links: + if self.auto_build_role_links and rules_removed: self.model.build_incremental_role_links(self.rm_map[ptype], PolicyOp.Policy_remove, "g", ptype, rules) return rules_removed @@ -292,7 +292,7 @@ def remove_filtered_named_grouping_policy(self, ptype, field_index, *field_value """removes a role inheritance rule from the current named policy, field filters can be specified.""" rule_removed = self._remove_filtered_policy_returns_effects("g", ptype, field_index, *field_values) - if self.auto_build_role_links: + if self.auto_build_role_links and rule_removed: self.model.build_incremental_role_links( self.rm_map[ptype], PolicyOp.Policy_remove, "g", ptype, rule_removed ) diff --git a/casbin/rbac/default_role_manager/role_manager.py b/casbin/rbac/default_role_manager/role_manager.py index 5ccd23a..e6f203d 100644 --- a/casbin/rbac/default_role_manager/role_manager.py +++ b/casbin/rbac/default_role_manager/role_manager.py @@ -149,7 +149,7 @@ def add_link(self, name1, name2, *domain): def delete_link(self, name1, name2, *domain): if Link(name1, name2) not in self.all_links: - raise RuntimeError(f"error: link between {name1} and {name2} does not exist") + return self.all_links.remove(Link(name1, name2)) user = self._get_role(name1)