Repository: casbin/pycasbin

Issue:
RBAC with Domain model ,get_all_subjects error
1、model.conf
![image](https://github.com/casbin/pycasbin/assets/32121721/9cd37638-a702-4138-8544-50fbdaa0e55f)
2、code：
![image](https://github.com/casbin/pycasbin/assets/32121721/5041e3a1-af32-41a5-8895-227289c759b2)
3、sqlite info
![image](https://github.com/casbin/pycasbin/assets/32121721/f66c78a6-a64c-43fe-9985-e18edde72b65)

question:
e.get_all_objects()  --> ['test.xxx.com']
it should be ['system:get','system:put','system:post']

Discussion:
@casbin-bot:  @techoner @Nekotoxin@leeqvip: `get_all_objects` is not applicable to this model configuration. 
You can put `dom` at the end, or use e.get_model().get_values_for_field_in_policy("p", "p", 2)@stonecoldyxp: > `get_all_objects` is not applicable to this model configuration. You can put `dom` at the end, or use e.get_model().get_values_for_field_in_policy("p", "p", 2)

case one (error):
 `get_all_objects` is not applicable to this model configuration. You can put `dom` at the end
mdoel.conf:
![image](https://github.com/casbin/pycasbin/assets/32121721/471daa32-56a5-44aa-bf6b-56325564e3b7)
sqlite info:
![image](https://github.com/casbin/pycasbin/assets/32121721/24717d36-899e-4898-9ed8-5b5b97a72045)
test result:
![image](https://github.com/casbin/pycasbin/assets/32121721/26c087ad-3c63-48f9-a5dc-de5e1db00caa)




@leeqvip: Oh, sorry, the order of `dom` cannot be changed due to hard coding.

It should be fixed as soon as possible.@Dobmod: The same problem also occurs in PHP-Casbin, 🤔perhaps they can be repaired together.@truc0: The [golang version of casbin](https://github.com/casbin/casbin) has the same problem too.

The root cause is `GetAllObjects` always fetch the index `1` of rules which `ptype = p`. However, according to [the document](https://casbin.org/docs/rbac-with-domains):

>  Conventionally, the domain token name in policy definition is `dom` and is placed as the second token `(sub, dom, obj, act)`. 

The `dom` (domain) field is fetched when RBAC with Domains is enabled. Code references:

- **Python:** [get_all_objects](https://github.com/casbin/pycasbin/blob/846cf2490648f344817d53280cfb3c4f03a91f26/casbin/management_enforcer.py#L32), [get_all_named_objects](https://github.com/casbin/pycasbin/blob/846cf2490648f344817d53280cfb3c4f03a91f26/casbin/management_enforcer.py#L37)
- **PHP:** [getAllObjects](https://github.com/php-casbin/php-casbin/blob/master/src/ManagementEnforcer.php#L45)
- **Golang:** [GetAllObjects](https://github.com/casbin/casbin/blob/master/management_api.go#L38)@github-actions: :tada: This issue has been resolved in version 1.36.2 :tada:

The release is available on:
- `v1.36.2`
- [GitHub release](https://github.com/casbin/pycasbin/releases/tag/v1.36.2)

Your **[semantic-release](https://github.com/semantic-release/semantic-release)** bot :package::rocket:

Solution patch:
diff --git a/casbin/constant/constants.py b/casbin/constant/constants.py
index c5b89b3..428dc13 100644
--- a/casbin/constant/constants.py
+++ b/casbin/constant/constants.py
@@ -13,6 +13,7 @@
 # limitations under the License.
 
 # Index constants
+ACTION_INDEX = "act"
 DOMAIN_INDEX = "dom"
 SUBJECT_INDEX = "sub"
 OBJECT_INDEX = "obj"
diff --git a/casbin/management_enforcer.py b/casbin/management_enforcer.py
index b374ce1..b1897fa 100644
--- a/casbin/management_enforcer.py
+++ b/casbin/management_enforcer.py
@@ -14,6 +14,7 @@
 
 from casbin.internal_enforcer import InternalEnforcer
 from casbin.model.policy_op import PolicyOp
+from casbin.constant.constants import ACTION_INDEX, SUBJECT_INDEX, OBJECT_INDEX
 
 
 class ManagementEnforcer(InternalEnforcer):
@@ -27,7 +28,8 @@ class ManagementEnforcer(InternalEnforcer):
 
     def get_all_named_subjects(self, ptype):
         """gets the list of subjects that show up in the current named policy."""
-        return self.model.get_values_for_field_in_policy("p", ptype, 0)
+        field_index = self.model.get_field_index(ptype, SUBJECT_INDEX)
+        return self.model.get_values_for_field_in_policy("p", ptype, field_index)
 
     def get_all_objects(self):
         """gets the list of objects that show up in the current policy."""
@@ -35,7 +37,8 @@ class ManagementEnforcer(InternalEnforcer):
 
     def get_all_named_objects(self, ptype):
         """gets the list of objects that show up in the current named policy."""
-        return self.model.get_values_for_field_in_policy("p", ptype, 1)
+        field_index = self.model.get_field_index(ptype, OBJECT_INDEX)
+        return self.model.get_values_for_field_in_policy("p", ptype, field_index)
 
     def get_all_actions(self):
         """gets the list of actions that show up in the current policy."""
@@ -43,7 +46,8 @@ class ManagementEnforcer(InternalEnforcer):
 
     def get_all_named_actions(self, ptype):
         """gets the list of actions that show up in the current named policy."""
-        return self.model.get_values_for_field_in_policy("p", ptype, 2)
+        field_index = self.model.get_field_index(ptype, ACTION_INDEX)
+        return self.model.get_values_for_field_in_policy("p", ptype, field_index)
 
     def get_all_roles(self):
         """gets the list of roles that show up in the current named policy."""


Test patch:
diff --git a/tests/test_management_api.py b/tests/test_management_api.py
index 84f5522..e924daa 100644
--- a/tests/test_management_api.py
+++ b/tests/test_management_api.py
@@ -38,6 +38,18 @@ class TestManagementApi(TestCaseBase):
         self.assertEqual(e.get_all_actions(), ["read", "write"])
         self.assertEqual(e.get_all_roles(), ["data2_admin"])
 
+    def test_get_list_with_domains(self):
+        e = self.get_enforcer(
+            get_examples("rbac_with_domains_model.conf"),
+            get_examples("rbac_with_domains_policy.csv"),
+            # True,
+        )
+
+        self.assertEqual(e.get_all_subjects(), ["admin"])
+        self.assertEqual(e.get_all_objects(), ["data1", "data2"])
+        self.assertEqual(e.get_all_actions(), ["read", "write"])
+        self.assertEqual(e.get_all_roles(), ["admin"])
+
     def test_get_policy_api(self):
         e = self.get_enforcer(
             get_examples("rbac_model.conf"),