Skip to content

Commit 8d4389c

Browse files
committed
your message
1 parent 45429e9 commit 8d4389c

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

casbin/management_enforcer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ def add_policies_ex(self, rules):
125125
"""
126126
return self.add_named_policies_ex("p", rules)
127127

128-
129128
def add_named_policy(self, ptype, *params):
130129
"""adds an authorization rule to the current named policy.
131130
@@ -248,6 +247,7 @@ def add_grouping_policies_ex(self, rules):
248247
But unlike AddGroupingPolicies, other non-existent rules are added instead of returning false directly.
249248
"""
250249
return self.add_named_grouping_policies_ex("g", rules)
250+
251251
def add_named_grouping_policy(self, ptype, *params):
252252
"""adds a named role inheritance rule to the current policy.
253253

casbin/synced_enforcer.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,14 @@ def add_policies(self, rules):
600600
with self._wl:
601601
return self._e.add_policies(rules)
602602

603+
def add_policies_ex(self, rules):
604+
"""Adds authorization rules to the current policy,skipping existing rules instead of returning an error.
605+
606+
If a rule already exists, it will be skipped,
607+
and other non-existent rules will be added."""
608+
with self._wl:
609+
return self._e.add_policies_ex(rules)
610+
603611
def add_named_policies(self, ptype, rules):
604612
"""adds authorization rules to the current named policy.
605613
@@ -608,6 +616,15 @@ def add_named_policies(self, ptype, rules):
608616
with self._wl:
609617
return self._e.add_named_policies(ptype, rules)
610618

619+
def add_named_policies_ex(self, ptype, rules):
620+
"""adds authorization rules to the current named policy, ignoring duplicates.
621+
622+
If the rule already exists, it will be skipped.
623+
Other non-existent rules are added.
624+
"""
625+
with self._wl:
626+
return self._e.add_named_policies_ex(ptype, rules)
627+
611628
def remove_policies(self, rules):
612629
"""removes authorization rules from the current policy."""
613630
with self._wl:
@@ -627,6 +644,16 @@ def add_grouping_policies(self, rules):
627644
with self._wl:
628645
return self._e.add_grouping_policies(rules)
629646

647+
def add_grouping_policies_ex(self, rules):
648+
"""adds grouping rules to the current policy, ignoring duplicates.
649+
650+
This is a wrapper for add_named_grouping_policies_ex with policy type "g".
651+
If the rule already exists, it will be skipped.
652+
Other non-existent rules are added.
653+
"""
654+
with self._wl:
655+
return self._e.add_named_grouping_policies_ex("g", rules)
656+
630657
def add_named_grouping_policies(self, ptype, rules):
631658
""" "adds named role inheritance rules to the current policy.
632659
@@ -635,6 +662,15 @@ def add_named_grouping_policies(self, ptype, rules):
635662
with self._wl:
636663
return self._e.add_named_grouping_policies(ptype, rules)
637664

665+
def add_named_grouping_policies_ex(self, ptype, rules):
666+
"""adds grouping rules to the specified policy type, ignoring duplicates.
667+
668+
If the rule already exists, it will be skipped.
669+
Other non-existent rules are added.
670+
"""
671+
with self._wl:
672+
return self._e.add_named_grouping_policies_ex(ptype, rules)
673+
638674
def remove_grouping_policies(self, rules):
639675
"""removes role inheritance rules from the current policy."""
640676
with self._wl:
@@ -685,3 +721,12 @@ def get_implicit_users_for_resource_by_domain(self, resource, domain):
685721
Compared to GetImplicitUsersForResource, domain is supported"""
686722
with self._rl:
687723
return self._e.get_implicit_users_for_resource_by_domain(resource, domain)
724+
725+
def self_add_policies_ex(self, sec, ptype, rules):
726+
"""adds authorization rules to the internal model without notifying the watcher.
727+
728+
If the rule already exists, it will be skipped.
729+
Other non-existent rules are added.
730+
"""
731+
with self._wl:
732+
return self._e.self_add_policies_ex(sec, ptype, rules)

0 commit comments

Comments
 (0)