From d97b058c5d53276a0740a4bb80b4f1424fc4dfe2 Mon Sep 17 00:00:00 2001 From: Carla Duarte Date: Tue, 26 Jan 2021 15:55:38 -0500 Subject: [PATCH] AA-568: fix start course bug --- .../course_home_api/outline/v1/views.py | 16 +++++++++------- .../tests/views/test_course_outline.py | 6 ++++-- openedx/features/course_experience/utils.py | 12 ++++++++++++ .../course_experience/views/course_home.py | 11 ++++++----- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lms/djangoapps/course_home_api/outline/v1/views.py b/lms/djangoapps/course_home_api/outline/v1/views.py index 93c111b0a5..ff749e4c3e 100644 --- a/lms/djangoapps/course_home_api/outline/v1/views.py +++ b/lms/djangoapps/course_home_api/outline/v1/views.py @@ -36,7 +36,7 @@ from openedx.features.course_experience.course_tools import CourseToolsPluginMan from openedx.features.course_experience.course_updates import ( dismiss_current_update_for_user, get_current_update_for_user, ) -from openedx.features.course_experience.utils import get_course_outline_block_tree +from openedx.features.course_experience.utils import get_course_outline_block_tree, get_start_block from openedx.features.discounts.utils import generate_offer_data from common.djangoapps.student.models import CourseEnrollment from xmodule.course_module import COURSE_VISIBILITY_PUBLIC, COURSE_VISIBILITY_PUBLIC_OUTLINE @@ -235,13 +235,15 @@ class OutlineTabView(RetrieveAPIView): try: resume_block = get_key_to_last_completed_block(request.user, course.id) resume_course['has_visited_course'] = True + resume_path = reverse('jump_to', kwargs={ + 'course_id': course_key_string, + 'location': str(resume_block) + }) + resume_course['url'] = request.build_absolute_uri(resume_path) except UnavailableCompletionData: - resume_block = course_usage_key - resume_path = reverse('jump_to', kwargs={ - 'course_id': course_key_string, - 'location': str(resume_block) - }) - resume_course['url'] = request.build_absolute_uri(resume_path) + start_block = get_start_block(course_blocks) + resume_course['url'] = start_block['lms_web_url'] + elif allow_public_outline or allow_public: course_blocks = get_course_outline_block_tree(request, course_key_string, None) if allow_public: diff --git a/openedx/features/course_experience/tests/views/test_course_outline.py b/openedx/features/course_experience/tests/views/test_course_outline.py index 28064fa484..5c6ccb7c53 100644 --- a/openedx/features/course_experience/tests/views/test_course_outline.py +++ b/openedx/features/course_experience/tests/views/test_course_outline.py @@ -580,7 +580,8 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT response = self.visit_course_home(course, start_count=1, resume_count=0) content = pq(response.content) - self.assertTrue(content('.action-resume-course').attr('href').endswith('/course/' + course.url_name)) + vertical = course.children[0].children[0].children[0] + self.assertTrue(content('.action-resume-course').attr('href').endswith('/vertical/' + vertical.url_name)) @override_settings(LMS_BASE='test_url:9999') def test_resume_course_with_completion_api(self): @@ -680,7 +681,8 @@ class TestCourseOutlineResumeCourse(SharedModuleStoreTestCase, CompletionWaffleT CourseEnrollment.get_enrollment(self.user, course.id).delete() response = self.visit_course_home(course, start_count=1, resume_count=0) content = pq(response.content) - self.assertTrue(content('.action-resume-course').attr('href').endswith('/course/' + course.url_name)) + vertical = course.children[0].children[0].children[0] + self.assertTrue(content('.action-resume-course').attr('href').endswith('/vertical/' + vertical.url_name)) @override_waffle_switch(ENABLE_COMPLETION_TRACKING_SWITCH, active=True) def test_course_outline_auto_open(self): diff --git a/openedx/features/course_experience/utils.py b/openedx/features/course_experience/utils.py index f5af09d5e4..e39e0b5dbb 100644 --- a/openedx/features/course_experience/utils.py +++ b/openedx/features/course_experience/utils.py @@ -254,6 +254,18 @@ def get_resume_block(block): return block +def get_start_block(block): + """ + Gets the deepest block to use as the starting block. + """ + if not block.get('children'): + return block + + first_child = block['children'][0] + + return get_start_block(first_child) + + def dates_banner_should_display(course_key, user): """ Return whether or not the reset banner should display, diff --git a/openedx/features/course_experience/views/course_home.py b/openedx/features/course_experience/views/course_home.py index 80d6686b47..298013f3dc 100644 --- a/openedx/features/course_experience/views/course_home.py +++ b/openedx/features/course_experience/views/course_home.py @@ -44,7 +44,7 @@ from .. import ( LATEST_UPDATE_FLAG, SHOW_UPGRADE_MSG_ON_COURSE_HOME, ) -from ..utils import get_course_outline_block_tree, get_resume_block +from ..utils import get_course_outline_block_tree, get_resume_block, get_start_block from .course_dates import CourseDatesFragmentView from .course_home_messages import CourseHomeMessageFragmentView from .course_outline import CourseOutlineFragmentView @@ -88,9 +88,9 @@ class CourseHomeFragmentView(EdxFragmentView): Returns information relevant to resume course functionality. Returns a tuple: (has_visited_course, resume_course_url) - has_visited_course: True if the user has ever visted the course, False otherwise. - resume_course_url: The URL of the 'resume course' block if the user has visited the course, - otherwise the URL of the course root. + has_visited_course: True if the user has ever completed a block, False otherwise. + resume_course_url: The URL of the 'resume course' block if the user has completed a block, + otherwise the URL of the first block to start the course. """ course_outline_root_block = get_course_outline_block_tree(request, course_id, request.user) @@ -99,7 +99,8 @@ class CourseHomeFragmentView(EdxFragmentView): if resume_block: resume_course_url = resume_block['lms_web_url'] else: - resume_course_url = course_outline_root_block['lms_web_url'] if course_outline_root_block else None + start_block = get_start_block(course_outline_root_block) if course_outline_root_block else None + resume_course_url = start_block['lms_web_url'] if start_block else None return has_visited_course, resume_course_url