Skip to content

Commit 58620c1

Browse files
committed
Make apps directly include the service URLs
1 parent d4960b8 commit 58620c1

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

ansible_base/rbac/api/serializers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,17 @@ def get_object_role_assignments(self, actor):
290290

291291
return assignment_list
292292

293+
def get_url(self, obj) -> str:
294+
return get_url_for_object(obj)
295+
293296

294297
class UserAccessListMixin(AccessListMixin, serializers.ModelSerializer):
295298
"controller uses auth.User model so this needs to be as compatible as possible, thus ModelSerializer"
296299

297300
object_role_assignments = serializers.SerializerMethodField()
298-
_expected_fields = ['id', 'username', 'summary_fields', 'object_role_assignments']
301+
_expected_fields = ['id', 'url', 'username', 'is_superuser', 'object_role_assignments']
299302

300303

301304
class TeamAccessListMixin(AccessListMixin, AbstractCommonModelSerializer):
302305
object_role_assignments = serializers.SerializerMethodField()
303-
_expected_fields = ['id', 'name', 'organization', 'summary_fields', 'object_role_assignments']
306+
_expected_fields = ['id', 'url', 'name', 'organization', 'object_role_assignments']

ansible_base/rbac/service_api/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
# These will be included by the resource registry
66
rbac_service_urls = [
7-
path('', include(service_router.urls)),
7+
path('service-index/', include(service_router.urls)),
88
]

ansible_base/resource_registry/urls.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from django.urls import include, path
44
from rest_framework import routers
55

6-
from ansible_base.rbac.service_api.urls import rbac_service_urls
76
from ansible_base.resource_registry import views
87

98
logger = logging.getLogger('ansible_base.resource-urls')
@@ -22,5 +21,4 @@
2221

2322
urlpatterns = [
2423
path('service-index/', include(service)),
25-
path('service-index/', include(rbac_service_urls)),
2624
]

docs/apps/rbac/for_app_developers.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ class MyRemoteObject(RemoteObject):
205205

206206
Then you would set `settings.RBAC_REMOTE_OBJECT_CLASS` to the import path for `MyRemoteObject`.
207207

208+
#### Add the Resource API URLs
209+
210+
```
211+
from ansible_base.rbac.service_api.urls import rbac_service_urls
212+
213+
urlpatterns = [
214+
...,
215+
path('service-index/', include(rbac_service_urls)),
216+
]
217+
```
218+
219+
This will add the following paths:
220+
- `service-index/role-types/`
221+
- `service-index/role-permissions/`
222+
- `service-index/role-user-assignments/`
223+
- `service-index/role-team-assignments/`
224+
225+
Both the role user & team assignment lists have a `assign/` and `unassign/` URL from that base.
226+
Those can be used to do one-shot synchronization of a single role assignment with
227+
global identifiers.
228+
208229
### Evaluating Permissions
209230

210231
The ultimate goal of this system is to evaluate what objects a user

docs/apps/resource_registry.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ This will add the following paths:
108108
- `service-index/resource-types/`: list of available resource types.
109109
- `service-index/metadata/`: service metadata (service type and ID)
110110

111+
Also consider adding the corresponding [RBAC urls](../apps/rbac/for_app_developers.md#add-the-resource-api-urls) under service-index.
112+
111113
## Fields
112114

113115
### AnsibleResourceField

test_app/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from ansible_base.authentication.views.ui_auth import UIAuth
77
from ansible_base.lib.dynamic_config.dynamic_urls import api_urls, api_version_urls, root_urls
8+
from ansible_base.rbac.service_api.urls import rbac_service_urls
89
from ansible_base.resource_registry.urls import urlpatterns as resource_api_urls
910
from test_app import views
1011
from test_app.router import router as test_app_router
@@ -20,6 +21,7 @@
2021
# Admin application
2122
re_path(r"^admin/", admin.site.urls, name="admin"),
2223
path('api/v1/', include(resource_api_urls)),
24+
path('api/v1/', include(rbac_service_urls)),
2325
path('api/v1/', views.api_root),
2426
path('api/v1/timeout_view/', views.timeout_view, name='test-timeout-view'),
2527
path('login/', include('rest_framework.urls')),

0 commit comments

Comments
 (0)