AA-568: fix start course bug

This commit is contained in:
Carla Duarte
2021-01-26 15:55:38 -05:00
parent b55a3f9680
commit d97b058c5d
4 changed files with 31 additions and 14 deletions

View File

@@ -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:

View File

@@ -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):

View File

@@ -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,

View File

@@ -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