def test_any_unfulfilled_milestones(self): """ Tests any_unfulfilled_milestones for invalid arguments with the app enabled """ with self.assertRaises(InvalidCourseKeyException): milestones_helpers.any_unfulfilled_milestones(None, self.user) with self.assertRaises(InvalidUserException): milestones_helpers.any_unfulfilled_milestones(self.course.id, None)
def _wrapper(self, request, *args, **kwargs): """ Expects kwargs to contain 'course_id'. Passes the course descriptor to the given decorated function. Raises 404 if access to course is disallowed. """ course_id = CourseKey.from_string(kwargs.pop('course_id')) with modulestore().bulk_operations(course_id): try: course = get_course_with_access(request.user, access_action, course_id, depth=depth) except Http404: # any_unfulfilled_milestones called a second time since has_access returns a bool if check_for_milestones and any_unfulfilled_milestones( course_id, request.user.id): message = { "developer_message": "Cannot access content with unfulfilled " "pre-requisites or unpassed entrance exam." } return response.Response( data=message, status=status.HTTP_204_NO_CONTENT) else: raise return func(self, request, course=course, *args, **kwargs)
def _wrapper(self, request, *args, **kwargs): """ Expects kwargs to contain 'course_id'. Passes the course descriptor to the given decorated function. Raises 404 if access to course is disallowed. """ course_id = CourseKey.from_string(kwargs.pop('course_id')) with modulestore().bulk_operations(course_id): try: course = get_course_with_access( request.user, access_action, course_id, depth=depth ) except Http404: # any_unfulfilled_milestones called a second time since has_access returns a bool if check_for_milestones and any_unfulfilled_milestones(course_id, request.user.id): message = { "developer_message": "Cannot access content with unfulfilled " "pre-requisites or unpassed entrance exam." } return response.Response(data=message, status=status.HTTP_204_NO_CONTENT) else: raise return func(self, request, course=course, *args, **kwargs)
def _has_fulfilled_all_milestones(user, course_id): """ Returns whether the given user has fulfilled all milestones for the given course. Arguments: course_id: ID of the course to check user_id: ID of the user to check """ return MilestoneAccessError() if any_unfulfilled_milestones(course_id, user.id) else ACCESS_GRANTED
def can_load_mobile_no_enroll_check(): """ Can this enrolled user access this course from a mobile device? Note: does not check for enrollment since it is assumed the caller has done so. """ return ( # check start date can_load() and # check mobile_available flag is_mobile_available_for_user(user, course) and # check staff access, if not then check for unfulfilled milestones (_has_staff_access_to_descriptor(user, course, course.id) or not any_unfulfilled_milestones(course.id, user.id)))
def can_load_mobile(): """ Can this user access this course from a mobile device? """ return ( # check start date can_load() and # check mobile_available flag is_mobile_available_for_user(user, course) and ( # either is a staff user or _has_staff_access_to_descriptor(user, course, course.id) or # check for unfulfilled milestones not any_unfulfilled_milestones(course.id, user.id)))
def can_load_mobile(): """ Can this user access this course from a mobile device? """ return ( # check start date can_load() and # check mobile_available flag is_mobile_available_for_user(user, course) and ( # either is a staff user or _has_staff_access_to_descriptor(user, course, course.id) or # check for unfulfilled milestones not any_unfulfilled_milestones(course.id, user.id) ) )
def can_load_mobile_no_enroll_check(): """ Can this enrolled user access this course from a mobile device? Note: does not check for enrollment since it is assumed the caller has done so. """ return ( # check start date can_load() and # check mobile_available flag is_mobile_available_for_user(user, course) and # check staff access, if not then check for unfulfilled milestones ( _has_staff_access_to_descriptor(user, course, course.id) or not any_unfulfilled_milestones(course.id, user.id) ) )
def _can_load_course_on_mobile(user, course): """ Checks if a user can view the given course on a mobile device. This function only checks mobile-specific access restrictions. Other access restrictions such as start date and the .visible_to_staff_only flag must be checked by callers in *addition* to the return value of this function. Arguments: user (User): the user whose course access we are checking. course (CourseDescriptor|CourseOverview): the course for which we are checking access. Returns: bool: whether the course can be accessed on mobile. """ return is_mobile_available_for_user(user, course) and ( _has_staff_access_to_descriptor(user, course, course.id) or not any_unfulfilled_milestones(course.id, user.id) )
def _can_load_course_on_mobile(user, course): """ Checks if a user can view the given course on a mobile device. This function only checks mobile-specific access restrictions. Other access restrictions such as start date and the .visible_to_staff_only flag must be checked by callers in *addition* to the return value of this function. Arguments: user (User): the user whose course access we are checking. course (CourseDescriptor|CourseOverview): the course for which we are checking access. Returns: bool: whether the course can be accessed on mobile. """ return ( is_mobile_available_for_user(user, course) and ( _has_staff_access_to_descriptor(user, course, course.id) or not any_unfulfilled_milestones(course.id, user.id) ) )