diff --git a/lms/djangoapps/course_home_api/dates/views.py b/lms/djangoapps/course_home_api/dates/views.py index 6c95f82349..0467af8a69 100644 --- a/lms/djangoapps/course_home_api/dates/views.py +++ b/lms/djangoapps/course_home_api/dates/views.py @@ -75,13 +75,19 @@ class DatesTabView(RetrieveAPIView): def get(self, request, *args, **kwargs): course_key_string = kwargs.get('course_key_string') course_key = CourseKey.from_string(course_key_string) + allow_not_started_courses = request.GET.get('allow_not_started_courses', False) # Enable NR tracing for this view based on course monitoring_utils.set_custom_attribute('course_id', course_key_string) monitoring_utils.set_custom_attribute('user_id', request.user.id) monitoring_utils.set_custom_attribute('is_staff', request.user.is_staff) - - course = get_course_or_403(request.user, 'load', course_key, check_if_enrolled=False) + course = get_course_or_403( + request.user, + 'load', + course_key, + check_if_enrolled=False, + allow_not_started_courses=allow_not_started_courses + ) is_staff = bool(has_access(request.user, 'staff', course_key)) _, request.user = setup_masquerade( diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index 0ff6a11a62..bebf3aefca 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -94,7 +94,16 @@ def get_course(course_id, depth=0): return course -def get_course_with_access(user, action, course_key, depth=0, check_if_enrolled=False, check_survey_complete=True, check_if_authenticated=False): # lint-amnesty, pylint: disable=line-too-long +def get_course_with_access( + user, + action, + course_key, + depth=0, + check_if_enrolled=False, + check_survey_complete=True, + check_if_authenticated=False, + allow_not_started_courses=False, +): """ Given a course_key, look up the corresponding course block, check that the user has the access to perform the specified action @@ -113,7 +122,15 @@ def get_course_with_access(user, action, course_key, depth=0, check_if_enrolled= be plugged in as additional callback checks for different actions. """ course = get_course_by_id(course_key, depth) - check_course_access_with_redirect(course, user, action, check_if_enrolled, check_survey_complete, check_if_authenticated) # lint-amnesty, pylint: disable=line-too-long + check_course_access_with_redirect( + course, + user, + action, + check_if_enrolled, + check_survey_complete, + check_if_authenticated, + allow_not_started_courses=allow_not_started_courses + ) return course @@ -202,7 +219,15 @@ def check_course_access( return non_staff_access_response -def check_course_access_with_redirect(course, user, action, check_if_enrolled=False, check_survey_complete=True, check_if_authenticated=False): # lint-amnesty, pylint: disable=line-too-long +def check_course_access_with_redirect( + course, + user, + action, + check_if_enrolled=False, + check_survey_complete=True, + check_if_authenticated=False, + allow_not_started_courses=False +): """ Check that the user has the access to perform the specified action on the course (CourseBlock|CourseOverview). @@ -216,6 +241,9 @@ def check_course_access_with_redirect(course, user, action, check_if_enrolled=Fa access_response = check_course_access(course, user, action, check_if_enrolled, check_survey_complete, check_if_authenticated) # lint-amnesty, pylint: disable=line-too-long if not access_response: + # StartDateError should be ignored + if isinstance(access_response, StartDateError) and allow_not_started_courses: + return # Redirect if StartDateError if isinstance(access_response, StartDateError): start_date = strftime_localized(course.start, 'SHORT_DATE')