1515from rest_framework .views import APIView
1616
1717from openedx_authz import api
18+ from openedx_authz .constants import permissions
1819from openedx_authz .rest_api .data import RoleOperationError , RoleOperationStatus
1920from openedx_authz .rest_api .decorators import authz_permissions , view_auth_classes
2021from openedx_authz .rest_api .utils import (
@@ -182,13 +183,13 @@ class RoleUserAPIView(APIView):
182183 "username": "john_doe",
183184184185 "full_name": "John Doe"
185- "roles": ["library_admin", "library_user" ]
186+ "roles": [roles.LIBRARY_ADMIN, roles.LIBRARY_USER ]
186187 },
187188 {
188189 "username": "jane_doe",
189190190191 "full_name": "Jane Doe"
191- "roles": ["library_user" ]
192+ "roles": [roles.LIBRARY_USER ]
192193 }
193194 ]
194195 }
@@ -223,7 +224,7 @@ class RoleUserAPIView(APIView):
223224 PUT /api/authz/v1/roles/users/ ::
224225
225226 {
226- "role": "library_admin" ,
227+ "role": roles.LIBRARY_ADMIN ,
227228 "scope": "lib:DemoX:CSPROB",
228229 "users": ["[email protected] ", "username2"] 229230 }
@@ -250,7 +251,7 @@ class RoleUserAPIView(APIView):
250251 status .HTTP_401_UNAUTHORIZED : "The user is not authenticated or does not have the required permissions" ,
251252 },
252253 )
253- @authz_permissions (["view_library_team" ])
254+ @authz_permissions ([permissions . VIEW_LIBRARY_TEAM ])
254255 def get (self , request : HttpRequest ) -> Response :
255256 """Retrieve all users with role assignments within a specific scope."""
256257 serializer = ListUsersInRoleWithScopeSerializer (data = request .query_params )
@@ -277,7 +278,7 @@ def get(self, request: HttpRequest) -> Response:
277278 status .HTTP_401_UNAUTHORIZED : "The user is not authenticated or does not have the required permissions" ,
278279 },
279280 )
280- @authz_permissions (["manage_library_team" ])
281+ @authz_permissions ([permissions . MANAGE_LIBRARY_TEAM ])
281282 def put (self , request : HttpRequest ) -> Response :
282283 """Assign multiple users to a specific role within a scope."""
283284 serializer = AddUsersToRoleWithScopeSerializer (data = request .data )
@@ -324,7 +325,7 @@ def put(self, request: HttpRequest) -> Response:
324325 status .HTTP_401_UNAUTHORIZED : "The user is not authenticated or does not have the required permissions" ,
325326 },
326327 )
327- @authz_permissions (["manage_library_team" ])
328+ @authz_permissions ([permissions . MANAGE_LIBRARY_TEAM ])
328329 def delete (self , request : HttpRequest ) -> Response :
329330 """Remove multiple users from a specific role within a scope."""
330331 serializer = RemoveUsersFromRoleWithScopeSerializer (data = request .query_params )
@@ -399,13 +400,15 @@ class RoleListView(APIView):
399400 "previous": null,
400401 "results": [
401402 {
402- "role": "library_author" ,
403+ "role": roles.LIBRARY_AUTHOR ,
403404 "permissions": ["delete_library_content", "edit_library"],
404405 "user_count": 5
405406 },
406407 {
407- "role": "library_user",
408- "permissions": ["view_library", "view_library_team", "reuse_library_content"],
408+ "role": roles.LIBRARY_USER,
409+ "permissions": [permissions.VIEW_LIBRARY,
410+ permissions.VIEW_LIBRARY_TEAM,
411+ permissions.REUSE_LIBRARY_CONTENT],
409412 "user_count": 12
410413 }
411414 ]
@@ -427,7 +430,7 @@ class RoleListView(APIView):
427430 status .HTTP_401_UNAUTHORIZED : "The user is not authenticated or does not have the required permissions" ,
428431 },
429432 )
430- @authz_permissions (["view_library_team" ])
433+ @authz_permissions ([permissions . VIEW_LIBRARY_TEAM ])
431434 def get (self , request : HttpRequest ) -> Response :
432435 """Retrieve all roles and their permissions for a specific scope."""
433436 serializer = ListRolesWithScopeSerializer (data = request .query_params )
0 commit comments