Пример #1
0
 def celebrations(self):
     """
     Returns a dict of celebrations that should be performed.
     """
     browser_timezone = self.request.query_params.get('browser_timezone', None)
     celebrations = get_celebrations_dict(self.effective_user, self.enrollment_object, self.course, browser_timezone)
     return celebrations
Пример #2
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')
        course_key = CourseKey.from_string(course_key_string)
        original_user_is_staff = has_access(request.user, 'staff',
                                            course_key).has_access

        _, request.user = setup_masquerade(
            request,
            course_key,
            staff_access=has_access(request.user, 'staff', course_key),
            reset_masquerade_data=True,
        )

        username = request.user.username if request.user.username else None
        course = course_detail(request, request.user.username, course_key)
        enrollment = CourseEnrollment.get_enrollment(request.user,
                                                     course_key_string)
        user_is_enrolled = bool(enrollment and enrollment.is_active)

        courseware_meta = CoursewareMeta(course_key, request,
                                         request.user.username)
        can_load_courseware = courseware_meta.is_microfrontend_enabled_for_user(
        )

        browser_timezone = self.request.query_params.get(
            'browser_timezone', None)
        celebrations = get_celebrations_dict(request.user, enrollment, course,
                                             browser_timezone)

        data = {
            'course_id': course.id,
            'username': username,
            'is_staff': has_access(request.user, 'staff',
                                   course_key).has_access,
            'original_user_is_staff': original_user_is_staff,
            'number': course.display_number_with_default,
            'org': course.display_org_with_default,
            'tabs': get_course_tab_list(request.user, course),
            'title': course.display_name_with_default,
            'is_self_paced': getattr(course, 'self_paced', False),
            'is_enrolled': user_is_enrolled,
            'can_load_courseware': can_load_courseware,
            'celebrations': celebrations,
        }
        context = self.get_serializer_context()
        context['course'] = course
        context['course_overview'] = course
        context['enrollment'] = enrollment
        serializer = self.get_serializer_class()(data, context=context)
        return Response(serializer.data)
Пример #3
0
    def get(self, request, *args, **kwargs):
        course_key_string = kwargs.get('course_key_string')
        course_key = CourseKey.from_string(course_key_string)
        original_user_is_global_staff = self.request.user.is_staff
        original_user_is_staff = has_access(request.user, 'staff',
                                            course_key).has_access

        course = course_detail(request, request.user.username, course_key)

        # We must compute course load access *before* setting up masquerading,
        # else course staff (who are not enrolled) will not be able view
        # their course from the perspective of a learner.
        load_access = check_course_access(
            course,
            request.user,
            'load',
            check_if_enrolled=True,
            check_if_authenticated=True,
        )

        _, request.user = setup_masquerade(
            request,
            course_key,
            staff_access=original_user_is_staff,
            reset_masquerade_data=True,
        )

        username = request.user.username if request.user.username else None
        enrollment = CourseEnrollment.get_enrollment(request.user,
                                                     course_key_string)
        user_is_enrolled = bool(enrollment and enrollment.is_active)

        can_load_courseware = courseware_mfe_is_visible(
            course_key=course_key,
            is_global_staff=original_user_is_global_staff,
            is_course_staff=original_user_is_staff)

        # User locale settings
        user_timezone_locale = user_timezone_locale_prefs(request)
        user_timezone = user_timezone_locale['user_timezone']

        browser_timezone = self.request.query_params.get(
            'browser_timezone', None)
        celebrations = get_celebrations_dict(
            request.user, enrollment, course,
            user_timezone if not None else browser_timezone)

        # Record course goals user activity for (web) learning mfe course tabs
        UserActivity.record_user_activity(request.user, course_key)

        data = {
            'course_id': course.id,
            'username': username,
            'is_staff': has_access(request.user, 'staff',
                                   course_key).has_access,
            'original_user_is_staff': original_user_is_staff,
            'number': course.display_number_with_default,
            'org': course.display_org_with_default,
            'start': course.start,
            'tabs': get_course_tab_list(request.user, course),
            'title': course.display_name_with_default,
            'is_self_paced': getattr(course, 'self_paced', False),
            'is_enrolled': user_is_enrolled,
            'course_access': load_access.to_json(),
            'can_load_courseware': can_load_courseware,
            'celebrations': celebrations,
            'user_timezone': user_timezone,
        }
        context = self.get_serializer_context()
        context['course'] = course
        context['course_overview'] = course
        context['enrollment'] = enrollment
        serializer = self.get_serializer_class()(data, context=context)
        return Response(serializer.data)