From 77a90a08ca904b7cd5dc1f72875c45c96b9e5b8f Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Fri, 25 Mar 2016 21:26:05 -0400 Subject: [PATCH] Add option to bypass course home Exposes an advanced setting in Studio allowing course teams to bypass the home tab when students arrive from the dashboard, sending them directly to course content. ECOM-3961. --- common/lib/xmodule/xmodule/course_module.py | 11 ++++++ .../xmodule/tests/test_course_module.py | 10 +++++ lms/djangoapps/courseware/tests/test_views.py | 38 +++++++++++++++++++ lms/djangoapps/courseware/views.py | 4 ++ 4 files changed, 63 insertions(+) diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 35607174d3..93e1481417 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -752,6 +752,17 @@ class CourseFields(object): scope=Scope.settings ) + bypass_home = Boolean( + display_name=_("Bypass Course Home"), + help=_( + "Bypass the course home tab when students arrive from the dashboard, " + "sending them directly to course content." + ), + default=False, + scope=Scope.settings, + deprecated=True + ) + enable_subsection_gating = Boolean( display_name=_("Enable Subsection Prerequisites"), help=_( diff --git a/common/lib/xmodule/xmodule/tests/test_course_module.py b/common/lib/xmodule/xmodule/tests/test_course_module.py index ffd63fed5b..1ccb50c0fa 100644 --- a/common/lib/xmodule/xmodule/tests/test_course_module.py +++ b/common/lib/xmodule/xmodule/tests/test_course_module.py @@ -365,6 +365,16 @@ class SelfPacedTestCase(unittest.TestCase): self.assertFalse(self.course.self_paced) +class BypassHomeTestCase(unittest.TestCase): + """Tests for setting which allows course home to be bypassed.""" + def setUp(self): + super(BypassHomeTestCase, self).setUp() + self.course = get_dummy_course('2012-12-02T12:00') + + def test_default(self): + self.assertFalse(self.course.bypass_home) + + class CourseDescriptorTestCase(unittest.TestCase): """ Tests for a select few functions from CourseDescriptor. diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index cae1b67c95..f8221cc247 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -652,6 +652,44 @@ class ViewsTestCase(ModuleStoreTestCase): response = self.client.get(url) self.assertRedirects(response, reverse('signin_user') + '?next=' + url) + def test_bypass_course_info(self): + course_id = unicode(self.course_key) + request = self.request_factory.get( + reverse('info', args=[course_id]) + ) + + # Middleware is not supported by the request factory. Simulate a + # logged-in user by setting request.user manually. + request.user = self.user + mako_middleware_process_request(request) + + self.assertFalse(self.course.bypass_home) + + self.assertIsNone(request.META.get('HTTP_REFERER')) # pylint: disable=no-member + response = views.course_info(request, course_id) + self.assertEqual(response.status_code, 200) + + request.META['HTTP_REFERER'] = reverse('dashboard') # pylint: disable=no-member + response = views.course_info(request, course_id) + self.assertEqual(response.status_code, 200) + + self.course.bypass_home = True + self.store.update_item(self.course, self.user.id) # pylint: disable=no-member + self.assertTrue(self.course.bypass_home) + + response = views.course_info(request, course_id) + + # assertRedirects would be great here, but it forces redirections to be absolute URLs. + self.assertEqual(response.status_code, 302) + self.assertEqual( + response.url, + reverse('courseware', args=[course_id]) + ) + + request.META['HTTP_REFERER'] = 'foo' # pylint: disable=no-member + response = views.course_info(request, course_id) + self.assertEqual(response.status_code, 200) + @attr('shard_1') # setting TIME_ZONE_DISPLAYED_FOR_DEADLINES explicitly diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index ee6df9b384..6eb261f7a3 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -694,6 +694,10 @@ def course_info(request, course_id): if request.user.is_authenticated() and survey.utils.must_answer_survey(course, user): return redirect(reverse('course_survey', args=[unicode(course.id)])) + is_from_dashboard = reverse('dashboard') in request.META.get('HTTP_REFERER', []) + if course.bypass_home and is_from_dashboard: + return redirect(reverse('courseware', args=[course_id])) + studio_url = get_studio_url(course, 'course_info') # link to where the student should go to enroll in the course: