Commit 77a90a08 by Renzo Lucioni

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.
parent 7222f9b0
...@@ -752,6 +752,17 @@ class CourseFields(object): ...@@ -752,6 +752,17 @@ class CourseFields(object):
scope=Scope.settings 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( enable_subsection_gating = Boolean(
display_name=_("Enable Subsection Prerequisites"), display_name=_("Enable Subsection Prerequisites"),
help=_( help=_(
......
...@@ -365,6 +365,16 @@ class SelfPacedTestCase(unittest.TestCase): ...@@ -365,6 +365,16 @@ class SelfPacedTestCase(unittest.TestCase):
self.assertFalse(self.course.self_paced) 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): class CourseDescriptorTestCase(unittest.TestCase):
""" """
Tests for a select few functions from CourseDescriptor. Tests for a select few functions from CourseDescriptor.
......
...@@ -652,6 +652,44 @@ class ViewsTestCase(ModuleStoreTestCase): ...@@ -652,6 +652,44 @@ class ViewsTestCase(ModuleStoreTestCase):
response = self.client.get(url) response = self.client.get(url)
self.assertRedirects(response, reverse('signin_user') + '?next=' + 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') @attr('shard_1')
# setting TIME_ZONE_DISPLAYED_FOR_DEADLINES explicitly # setting TIME_ZONE_DISPLAYED_FOR_DEADLINES explicitly
......
...@@ -694,6 +694,10 @@ def course_info(request, course_id): ...@@ -694,6 +694,10 @@ def course_info(request, course_id):
if request.user.is_authenticated() and survey.utils.must_answer_survey(course, user): if request.user.is_authenticated() and survey.utils.must_answer_survey(course, user):
return redirect(reverse('course_survey', args=[unicode(course.id)])) 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') studio_url = get_studio_url(course, 'course_info')
# link to where the student should go to enroll in the course: # link to where the student should go to enroll in the course:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment