Skip to content

Commit 2c5a932

Browse files
committed
add feat: add new add-uers API
1 parent a523245 commit 2c5a932

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

casbin/management_enforcer.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ def add_policies(self, rules):
117117
"""
118118
return self.add_named_policies("p", rules)
119119

120+
def add_policies_ex(self, rules):
121+
"""adds authorization rules to the current policy.
122+
123+
If the rule already exists, the rule will not be added.
124+
But unlike AddPolicies, other non-existent rules are added instead of returning false directly.
125+
"""
126+
return self.add_named_policies_ex("p", rules)
127+
128+
120129
def add_named_policy(self, ptype, *params):
121130
"""adds an authorization rule to the current named policy.
122131
@@ -139,6 +148,14 @@ def add_named_policies(self, ptype, rules):
139148
Otherwise the function returns true for the corresponding by adding the new rule."""
140149
return self._add_policies("p", ptype, rules)
141150

151+
def add_named_policies_ex(self, ptype, rules):
152+
"""adds authorization rules to the current named policy.
153+
154+
If the rule already exists, the rule will not be added.
155+
But unlike AddNamedPolicies, other non-existent rules are added instead of returning false directly.
156+
"""
157+
return self._add_policies("p", ptype, rules)
158+
142159
def update_policy(self, old_rule, new_rule):
143160
"""updates an authorization rule from the current policy."""
144161
return self.update_named_policy("p", old_rule, new_rule)
@@ -224,6 +241,13 @@ def add_grouping_policies(self, rules):
224241
"""
225242
return self.add_named_grouping_policies("g", rules)
226243

244+
def add_grouping_policies_ex(self, rules):
245+
"""adds role inheritance rules to the current policy.
246+
247+
If the rule already exists, the rule will not be added.
248+
But unlike AddGroupingPolicies, other non-existent rules are added instead of returning false directly.
249+
"""
250+
return self.add_named_grouping_policies_ex("g", rules)
227251
def add_named_grouping_policy(self, ptype, *params):
228252
"""adds a named role inheritance rule to the current policy.
229253
@@ -259,6 +283,17 @@ def add_named_grouping_policies(self, ptype, rules):
259283

260284
return rules_added
261285

286+
def add_named_grouping_policies_ex(self, ptype, rules):
287+
"""adds named role inheritance rules to the current policy.
288+
289+
If the rule already exists, the rule will not be added.
290+
But unlike AddNamedGroupingPolicies, other non-existent rules are added instead of returning false directly."""
291+
rules_added = self._add_policies_ex("g", ptype, rules)
292+
if self.auto_build_role_links:
293+
self.model.build_incremental_role_links(self.rm_map[ptype], PolicyOp.Policy_add, "g", ptype, rules)
294+
295+
return rules_added
296+
262297
def remove_grouping_policy(self, *params):
263298
"""removes a role inheritance rule from the current policy."""
264299
return self.remove_named_grouping_policy("g", *params)
@@ -309,3 +344,6 @@ def remove_filtered_named_grouping_policy(self, ptype, field_index, *field_value
309344
def add_function(self, name, func):
310345
"""adds a customized function."""
311346
self.fm.add_function(name, func)
347+
348+
def self_add_policies_ex(self, sec, ptype, rules):
349+
return self._add_policies_without_notify(sec, ptype, rules, True)

0 commit comments

Comments
 (0)