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

fix: avoid raising exception in remove_grouping_policy #257

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions casbin/management_enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ 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

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
Expand All @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion casbin/rbac/default_role_manager/role_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down