Skip to content

Commit

Permalink
feat: allow oauth2 on all views
Browse files Browse the repository at this point in the history
  • Loading branch information
shadinaif committed Nov 26, 2024
1 parent 115802c commit 903da3f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion futurex_openedx_extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""One-line description for README and other doc files."""

__version__ = '0.9.14'
__version__ = '0.9.15'
21 changes: 18 additions & 3 deletions futurex_openedx_extensions/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
COURSE_ACCESS_ROLES_SUPPORTED_READ,
COURSE_STATUS_SELF_PREFIX,
COURSE_STATUSES,
FX_VIEW_DEFAULT_AUTH_CLASSES,
)
from futurex_openedx_extensions.helpers.converters import error_details_to_dictionary
from futurex_openedx_extensions.helpers.exceptions import FXCodedException, FXExceptionCodes
Expand All @@ -69,6 +70,8 @@
from futurex_openedx_extensions.helpers.tenants import get_tenants_info
from futurex_openedx_extensions.helpers.users import get_user_by_key

default_auth_classes = FX_VIEW_DEFAULT_AUTH_CLASSES.copy()


class TotalCountsView(APIView, FXViewRoleInfoMixin):
"""
Expand All @@ -91,6 +94,7 @@ class TotalCountsView(APIView, FXViewRoleInfoMixin):
STAT_LEARNERS: 'learners_count',
}

authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
fx_view_name = 'total_counts_statistics'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
Expand Down Expand Up @@ -182,8 +186,9 @@ def get(self, request: Any, *args: Any, **kwargs: Any) -> Response | JsonRespons

class LearnersView(ListAPIView, FXViewRoleInfoMixin):
"""View to get the list of learners"""
serializer_class = serializers.LearnerDetailsSerializer
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
serializer_class = serializers.LearnerDetailsSerializer
pagination_class = DefaultPagination
fx_view_name = 'learners_list'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
Expand All @@ -203,8 +208,9 @@ def get_queryset(self) -> QuerySet:

class CoursesView(ListAPIView, FXViewRoleInfoMixin):
"""View to get the list of courses"""
serializer_class = serializers.CourseDetailsSerializer
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
serializer_class = serializers.CourseDetailsSerializer
pagination_class = DefaultPagination
filter_backends = [DefaultOrderingFilter]
ordering_fields = [
Expand All @@ -231,6 +237,7 @@ def get_queryset(self) -> QuerySet:

class CourseStatusesView(APIView, FXViewRoleInfoMixin):
"""View to get the course statuses"""
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
fx_view_name = 'course_statuses'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
Expand Down Expand Up @@ -264,6 +271,7 @@ def get(self, request: Any, *args: Any, **kwargs: Any) -> JsonResponse:

class LearnerInfoView(APIView, FXViewRoleInfoMixin):
"""View to get the information of a learner"""
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
fx_view_name = 'learner_detailed_info'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
Expand Down Expand Up @@ -298,8 +306,9 @@ def get(self, request: Any, username: str, *args: Any, **kwargs: Any) -> JsonRes

class DataExportManagementView(viewsets.ModelViewSet, FXViewRoleInfoMixin): # pylint: disable=too-many-ancestors
"""View to list and retrieve data export tasks."""
serializer_class = serializers.DataExportTaskSerializer
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
serializer_class = serializers.DataExportTaskSerializer
pagination_class = DefaultPagination
fx_view_name = 'exported_files_data'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
Expand Down Expand Up @@ -328,6 +337,7 @@ def get_object(self) -> DataExportTask:

class LearnerCoursesView(APIView, FXViewRoleInfoMixin):
"""View to get the list of courses for a learner"""
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
pagination_class = DefaultPagination
fx_view_name = 'learner_courses'
Expand Down Expand Up @@ -399,6 +409,7 @@ def get(self, request: Any, *args: Any, **kwargs: Any) -> JsonResponse: # pylin

class LearnersDetailsForCourseView(ExportCSVMixin, ListAPIView, FXViewRoleInfoMixin):
"""View to get the list of learners for a course"""
authentication_classes = default_auth_classes
serializer_class = serializers.LearnerDetailsForCourseSerializer
permission_classes = [FXHasTenantCourseAccess]
pagination_class = DefaultPagination
Expand Down Expand Up @@ -467,6 +478,7 @@ def get_serializer_context(self) -> Dict[str, Any]:

class GlobalRatingView(APIView, FXViewRoleInfoMixin):
"""View to get the global rating"""
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
fx_view_name = 'global_rating'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
Expand Down Expand Up @@ -494,6 +506,7 @@ def get(self, request: Any, *args: Any, **kwargs: Any) -> JsonResponse:

class UserRolesManagementView(viewsets.ModelViewSet, FXViewRoleInfoMixin): # pylint: disable=too-many-ancestors
"""View to get the user roles"""
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantAllCoursesAccess]
fx_view_name = 'user_roles'
fx_default_read_only_roles = ['org_course_creator_group']
Expand Down Expand Up @@ -656,6 +669,7 @@ def destroy(self, request: Any, *args: Any, **kwargs: Any) -> Response:

class MyRolesView(APIView, FXViewRoleInfoMixin):
"""View to get the user roles of the caller"""
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
fx_view_name = 'my_roles'
fx_default_read_only_roles = COURSE_ACCESS_ROLES_SUPPORTED_READ.copy()
Expand All @@ -672,6 +686,7 @@ def get(self, request: Any, *args: Any, **kwargs: Any) -> JsonResponse:

class ClickhouseQueryView(APIView, FXViewRoleInfoMixin):
"""View to get the Clickhouse query"""
authentication_classes = default_auth_classes
permission_classes = [FXHasTenantCourseAccess]
fx_view_name = 'clickhouse_query_fetcher'
fx_default_read_only_roles = ['staff', 'instructor', 'data_researcher', 'org_course_creator_group']
Expand Down
5 changes: 5 additions & 0 deletions futurex_openedx_extensions/helpers/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""Constants for the FutureX Open edX Extensions app."""
from openedx.core.lib.api.authentication import BearerAuthentication
from rest_framework.authentication import SessionAuthentication

CACHE_NAME_ALL_COURSE_ORG_FILTER_LIST = 'fx_course_org_filter_list'
CACHE_NAME_ALL_TENANTS_INFO = 'fx_tenants_info'
CACHE_NAME_ALL_VIEW_ROLES = 'fx_view_roles'
Expand Down Expand Up @@ -112,3 +115,5 @@
USER_KEY_TYPE_NOT_ID = 'username/email'

CSV_TASK_LIMIT_PER_USER = 3

FX_VIEW_DEFAULT_AUTH_CLASSES = [SessionAuthentication, BearerAuthentication]
7 changes: 7 additions & 0 deletions test_utils/edx_platform_mocks/fake_models/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ class OrgRole(RoleBase): # pylint: disable=too-few-public-methods


REGISTERED_ACCESS_ROLES = {}


class BearerAuthentication: # pylint: disable=too-few-public-methods
"""Mock"""
def authenticate(self, request): # pylint: disable=no-self-use
"""Mock"""
return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""edx-platform Mocks"""
from fake_models.classes import BearerAuthentication # pylint: disable=unused-import

0 comments on commit 903da3f

Please sign in to comment.