Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/openedx_authz/engine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
batch_assign_role_to_users_in_scope,
batch_unassign_role_from_users,
)
from openedx_authz.constants.roles import (
from openedx_authz.authz import (
LEGACY_COURSE_ROLE_EQUIVALENCES,
LIBRARY_ADMIN,
LIBRARY_AUTHOR,
Expand Down
25 changes: 14 additions & 11 deletions src/openedx_authz/rest_api/v1/admin_console/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
get_visible_role_assignments_for_user,
get_visible_user_role_assignments_filtered_by_current_user,
)
from openedx_authz.constants import permissions
from openedx_authz.authz import (
COURSES_VIEW_COURSE_TEAM,
VIEW_LIBRARY_TEAM,
)
from openedx_authz.models.scopes import get_content_library_model, get_course_overview_model
from openedx_authz.rest_api.data import ScopesQuerySetFields, ScopesTypeField
from openedx_authz.rest_api.decorators import authz_permissions, view_auth_classes
Expand Down Expand Up @@ -73,8 +76,8 @@
@method_decorator(
authz_permissions(
[
permissions.VIEW_LIBRARY_TEAM.identifier,
permissions.COURSES_VIEW_COURSE_TEAM.identifier,
VIEW_LIBRARY_TEAM.identifier,
COURSES_VIEW_COURSE_TEAM.identifier,
]
),
name="get",
Expand Down Expand Up @@ -183,8 +186,8 @@ def get_queryset(self) -> QuerySet:
@method_decorator(
authz_permissions(
[
permissions.VIEW_LIBRARY_TEAM.identifier,
permissions.COURSES_VIEW_COURSE_TEAM.identifier,
VIEW_LIBRARY_TEAM.identifier,
COURSES_VIEW_COURSE_TEAM.identifier,
]
),
name="get",
Expand Down Expand Up @@ -639,8 +642,8 @@ class TeamMembersAPIView(APIView):
)
@authz_permissions(
[
permissions.VIEW_LIBRARY_TEAM.identifier,
permissions.COURSES_VIEW_COURSE_TEAM.identifier,
VIEW_LIBRARY_TEAM.identifier,
COURSES_VIEW_COURSE_TEAM.identifier,
]
)
def get(self, request: HttpRequest) -> Response:
Expand Down Expand Up @@ -765,8 +768,8 @@ class TeamMemberAssignmentsAPIView(APIView):
)
@authz_permissions(
[
permissions.VIEW_LIBRARY_TEAM.identifier,
permissions.COURSES_VIEW_COURSE_TEAM.identifier,
VIEW_LIBRARY_TEAM.identifier,
COURSES_VIEW_COURSE_TEAM.identifier,
]
)
def get(self, request: HttpRequest, username: str) -> Response:
Expand Down Expand Up @@ -887,8 +890,8 @@ class AssignmentsAPIView(APIView):
)
@authz_permissions(
[
permissions.VIEW_LIBRARY_TEAM.identifier,
permissions.COURSES_VIEW_COURSE_TEAM.identifier,
VIEW_LIBRARY_TEAM.identifier,
COURSES_VIEW_COURSE_TEAM.identifier,
]
)
def get(self, request: HttpRequest) -> Response:
Expand Down
2 changes: 1 addition & 1 deletion src/openedx_authz/rest_api/v1/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rest_framework.permissions import BasePermission

from openedx_authz import api
from openedx_authz.constants.permissions import COURSES_VIEW_COURSE_TEAM, VIEW_LIBRARY_TEAM
from openedx_authz.authz import COURSES_VIEW_COURSE_TEAM, VIEW_LIBRARY_TEAM
from openedx_authz.rest_api.data import ScopesTypeField
from openedx_authz.rest_api.utils import parse_scope_types

Expand Down
18 changes: 12 additions & 6 deletions src/openedx_authz/rest_api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@

from openedx_authz import api
from openedx_authz.api.utils import get_user_map
from openedx_authz.constants import permissions
from openedx_authz.constants.roles import COURSE_ADMIN, LIBRARY_ADMIN
from openedx_authz.authz import (
COURSE_ADMIN,
COURSES_MANAGE_COURSE_TEAM,
COURSES_VIEW_COURSE_TEAM,
LIBRARY_ADMIN,
MANAGE_LIBRARY_TEAM,
VIEW_LIBRARY,
)
from openedx_authz.filters import PermissionValidationRequested, RoleAssignmentRequested, RoleRemovalRequested
from openedx_authz.rest_api.data import RoleOperationError, RoleOperationStatus
from openedx_authz.rest_api.decorators import authz_permissions, view_auth_classes
Expand Down Expand Up @@ -287,7 +293,7 @@ class RoleUserAPIView(APIView):
status.HTTP_401_UNAUTHORIZED: "The user is not authenticated or does not have the required permissions",
},
)
@authz_permissions([permissions.VIEW_LIBRARY.identifier, permissions.COURSES_VIEW_COURSE_TEAM.identifier])
@authz_permissions([VIEW_LIBRARY.identifier, COURSES_VIEW_COURSE_TEAM.identifier])
def get(self, request: HttpRequest) -> Response:
"""Retrieve all users with role assignments within a specific scope."""
serializer = ListUsersInRoleWithScopeSerializer(data=request.query_params)
Expand All @@ -314,7 +320,7 @@ def get(self, request: HttpRequest) -> Response:
status.HTTP_401_UNAUTHORIZED: "The user is not authenticated or does not have the required permissions",
},
)
@authz_permissions([permissions.MANAGE_LIBRARY_TEAM.identifier, permissions.COURSES_MANAGE_COURSE_TEAM.identifier])
@authz_permissions([MANAGE_LIBRARY_TEAM.identifier, COURSES_MANAGE_COURSE_TEAM.identifier])
def put(self, request: HttpRequest) -> Response:
"""Assign multiple users to a specific role within one or more scopes."""
serializer = AddUsersToRoleWithScopeSerializer(data=request.data)
Expand Down Expand Up @@ -362,7 +368,7 @@ def put(self, request: HttpRequest) -> Response:
status.HTTP_401_UNAUTHORIZED: "The user is not authenticated or does not have the required permissions",
},
)
@authz_permissions([permissions.MANAGE_LIBRARY_TEAM.identifier, permissions.COURSES_MANAGE_COURSE_TEAM.identifier])
@authz_permissions([MANAGE_LIBRARY_TEAM.identifier, COURSES_MANAGE_COURSE_TEAM.identifier])
def delete(self, request: HttpRequest) -> Response:
"""Remove multiple users from a specific role within a scope."""
serializer = RemoveUsersFromRoleWithScopeSerializer(data=request.query_params)
Expand Down Expand Up @@ -535,7 +541,7 @@ class UserValidationAPIView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "An unexpected error occurred while validating users",
},
)
@authz_permissions([permissions.MANAGE_LIBRARY_TEAM.identifier, permissions.COURSES_MANAGE_COURSE_TEAM.identifier])
@authz_permissions([MANAGE_LIBRARY_TEAM.identifier, COURSES_MANAGE_COURSE_TEAM.identifier])
def post(self, request: HttpRequest) -> Response:
"""Validates the provided usernames or emails correspond to existing users."""
request_serializer = UserValidationAPIViewSerializer(data=request.data)
Expand Down
29 changes: 17 additions & 12 deletions src/openedx_authz/tests/api/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
SubjectData,
UserData,
)
from openedx_authz.constants import permissions, roles
from openedx_authz.authz import (
COURSES_MANAGE_COURSE_TEAM,
COURSES_VIEW_COURSE_TEAM,
DELETE_LIBRARY,
LIBRARY_ADMIN,
MANAGE_LIBRARY_TEAM,
VIEW_LIBRARY_TEAM,
)
from openedx_authz.tests.stubs.models import ContentLibrary, CourseOverview, Organization


Expand Down Expand Up @@ -713,7 +720,7 @@ def test_user_data_str_and_repr(self, external_key, expected_str, expected_repr)
("read", "Read", "act^read"),
("write", "Write", "act^write"),
(
permissions.DELETE_LIBRARY.identifier,
DELETE_LIBRARY.identifier,
"Content Libraries > Delete Library",
"act^content_libraries.delete_library",
),
Expand Down Expand Up @@ -757,7 +764,7 @@ def test_scope_data_str_and_repr(self, external_key, expected_str, expected_repr

@data(
("instructor", "Instructor", "role^instructor"),
(roles.LIBRARY_ADMIN.external_key, "Library Admin", "role^library_admin"),
(LIBRARY_ADMIN.external_key, "Library Admin", "role^library_admin"),
("course_staff", "Course Staff", "role^course_staff"),
)
@unpack
Expand Down Expand Up @@ -798,7 +805,7 @@ def test_role_data_str_with_permissions(self):
("read", "allow", "Read - allow", "act^read => allow"),
("write", "deny", "Write - deny", "act^write => deny"),
(
permissions.DELETE_LIBRARY.identifier,
DELETE_LIBRARY.identifier,
"allow",
"Content Libraries > Delete Library - allow",
"act^content_libraries.delete_library => allow",
Expand Down Expand Up @@ -829,7 +836,7 @@ def test_role_assignment_data_str(self):
"""
user = UserData(external_key="john_doe")
role1 = RoleData(external_key="instructor")
role2 = RoleData(external_key=roles.LIBRARY_ADMIN.external_key)
role2 = RoleData(external_key=LIBRARY_ADMIN.external_key)
scope = ContentLibraryData(external_key="lib:DemoX:CSPROB")
assignment = RoleAssignmentData(subject=user, roles=[role1, role2], scope=scope)

Expand All @@ -846,7 +853,7 @@ def test_role_assignment_data_repr(self):
"""
user = UserData(external_key="john_doe")
role1 = RoleData(external_key="instructor")
role2 = RoleData(external_key=roles.LIBRARY_ADMIN.external_key)
role2 = RoleData(external_key=LIBRARY_ADMIN.external_key)
scope = ContentLibraryData(external_key="lib:DemoX:CSPROB")
assignment = RoleAssignmentData(subject=user, roles=[role1, role2], scope=scope)

Expand Down Expand Up @@ -1227,15 +1234,13 @@ def test_dynamic_instantiation_via_scope_data(self):

def test_get_admin_view_permission(self):
"""View permission matches course team view permission."""
self.assertEqual(
PlatformCourseOverviewGlobData.get_admin_view_permission(), permissions.COURSES_VIEW_COURSE_TEAM
)
self.assertEqual(PlatformCourseOverviewGlobData.get_admin_view_permission(), COURSES_VIEW_COURSE_TEAM)

def test_get_admin_manage_permission(self):
"""Manage permission matches course team manage permission."""
self.assertEqual(
PlatformCourseOverviewGlobData.get_admin_manage_permission(),
permissions.COURSES_MANAGE_COURSE_TEAM,
COURSES_MANAGE_COURSE_TEAM,
)

def test_is_platform_glob(self):
Expand Down Expand Up @@ -1303,13 +1308,13 @@ def test_dynamic_instantiation_via_scope_data(self):

def test_get_admin_view_permission(self):
"""View permission matches library team view permission."""
self.assertEqual(PlatformContentLibraryGlobData.get_admin_view_permission(), permissions.VIEW_LIBRARY_TEAM)
self.assertEqual(PlatformContentLibraryGlobData.get_admin_view_permission(), VIEW_LIBRARY_TEAM)

def test_get_admin_manage_permission(self):
"""Manage permission matches library team manage permission."""
self.assertEqual(
PlatformContentLibraryGlobData.get_admin_manage_permission(),
permissions.MANAGE_LIBRARY_TEAM,
MANAGE_LIBRARY_TEAM,
)

def test_is_platform_glob(self):
Expand Down
Loading
Loading