Skip to content

Commit 9fe3df2

Browse files
committed
chore: replace field name with constant in ManagementEnforcer
1 parent 54bc5a0 commit 9fe3df2

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

casbin/constant/constants.py

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
# Index constants
16+
ACTION_INDEX = "act"
1617
DOMAIN_INDEX = "dom"
1718
SUBJECT_INDEX = "sub"
1819
OBJECT_INDEX = "obj"

casbin/management_enforcer.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from casbin.internal_enforcer import InternalEnforcer
1616
from casbin.model.policy_op import PolicyOp
17+
from casbin.constant.constants import ACTION_INDEX, SUBJECT_INDEX, OBJECT_INDEX
1718

1819

1920
class ManagementEnforcer(InternalEnforcer):
@@ -27,7 +28,7 @@ def get_all_subjects(self):
2728

2829
def get_all_named_subjects(self, ptype):
2930
"""gets the list of subjects that show up in the current named policy."""
30-
field_index = self.model.get_field_index(ptype, "sub")
31+
field_index = self.model.get_field_index(ptype, SUBJECT_INDEX)
3132
return self.model.get_values_for_field_in_policy("p", ptype, field_index)
3233

3334
def get_all_objects(self):
@@ -36,7 +37,7 @@ def get_all_objects(self):
3637

3738
def get_all_named_objects(self, ptype):
3839
"""gets the list of objects that show up in the current named policy."""
39-
field_index = self.model.get_field_index(ptype, "obj")
40+
field_index = self.model.get_field_index(ptype, OBJECT_INDEX)
4041
return self.model.get_values_for_field_in_policy("p", ptype, field_index)
4142

4243
def get_all_actions(self):
@@ -45,7 +46,7 @@ def get_all_actions(self):
4546

4647
def get_all_named_actions(self, ptype):
4748
"""gets the list of actions that show up in the current named policy."""
48-
field_index = self.model.get_field_index(ptype, "act")
49+
field_index = self.model.get_field_index(ptype, ACTION_INDEX)
4950
return self.model.get_values_for_field_in_policy("p", ptype, field_index)
5051

5152
def get_all_roles(self):

0 commit comments

Comments
 (0)