@@ -138,3 +138,43 @@ def test_no_duplicates_team(team, inv_rd, inventory, org_inv_rd, admin_api_clien
138
138
response = admin_api_client .get (url )
139
139
assert response .status_code == 200 , response .data
140
140
assert response .data ['count' ] == 1 , response .data
141
+
142
+
143
+ @pytest .mark .django_db
144
+ def test_org_admin_role_user_access_bug (organization , org_admin_rd ):
145
+ """
146
+ Test for AAP-52187: Org admin gets 403 on role_user_access despite having proper permissions.
147
+
148
+ This test demonstrates the RBAC evaluation bug where:
149
+ - Org admin can GET /organizations/X/ (works correctly)
150
+ - Same org admin gets 403 on /role_user_access/shared.organization/X/ (bug)
151
+ - Both should work since the user has shared.view_organization permission
152
+ """
153
+ from rest_framework .test import APIClient
154
+
155
+ # Create org admin user for AAP-52187 reproduction
156
+ org_admin_user = User .objects .create (username = 'aap52187-org-admin-test-user' )
157
+
158
+ # Give user Organization Admin role on the organization
159
+ org_admin_rd .give_permission (org_admin_user , organization )
160
+
161
+ # Create API client for the org admin user
162
+ client = APIClient ()
163
+ client .force_authenticate (user = org_admin_user )
164
+
165
+ # Test 1: Org admin should be able to view the organization directly
166
+ org_detail_url = get_relative_url ('organization-detail' , kwargs = {'pk' : organization .pk })
167
+ response = client .get (org_detail_url )
168
+ assert response .status_code == 200 , f"Org admin should be able to view organization directly: { response .data } "
169
+
170
+ # Test 2: Org admin should be able to view role user access for the same organization
171
+ # This is currently broken due to has_obj_perm evaluation bug in UserAccessViewSet
172
+ role_access_url = get_relative_url ('role-user-access' , kwargs = {'pk' : organization .pk , 'model_name' : 'shared.organization' })
173
+ response = client .get (role_access_url )
174
+
175
+ # This assertion will fail with current bug, demonstrating the issue
176
+ assert response .status_code == 200 , (
177
+ f"AAP-52187 BUG: Org admin should be able to view role access for organization they manage. "
178
+ f"User has shared.view_organization permission and can access org detail endpoint, "
179
+ f"but role_user_access fails with: { response .status_code } { response .data } "
180
+ )
0 commit comments