Redirect to dashboard from non-live courses.
TNL-2693
This commit is contained in:
@@ -3,10 +3,13 @@ Test the course_info xblock
|
||||
"""
|
||||
import mock
|
||||
from nose.plugins.attrib import attr
|
||||
from urllib import urlencode
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from opaque_keys.edx.locations import SlashSeparatedCourseKey
|
||||
|
||||
from util.date_utils import strftime_localized
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.django_utils import TEST_DATA_MIXED_CLOSED_MODULESTORE
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
|
||||
@@ -62,6 +65,24 @@ class CourseInfoTestCase(LoginEnrollmentTestCase, ModuleStoreTestCase):
|
||||
).exists()
|
||||
self.assertFalse(enrollment_exists)
|
||||
|
||||
@mock.patch.dict(settings.FEATURES, {'DISABLE_START_DATES': False})
|
||||
def test_non_live_course(self):
|
||||
"""Ensure that a user accessing a non-live course sees a redirect to
|
||||
the student dashboard, not a 404.
|
||||
"""
|
||||
self.setup_user()
|
||||
self.enroll(self.course)
|
||||
url = reverse('info', args=[unicode(self.course.id)])
|
||||
response = self.client.get(url)
|
||||
start_date = strftime_localized(self.course.start, 'SHORT_DATE')
|
||||
self.assertRedirects(response, '{0}?{1}'.format(reverse('dashboard'), urlencode({'notlive': start_date})))
|
||||
|
||||
def test_nonexistent_course(self):
|
||||
self.setup_user()
|
||||
url = reverse('info', args=['not/a/course'])
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
@attr('shard_1')
|
||||
class CourseInfoTestCaseXML(LoginEnrollmentTestCase, ModuleStoreTestCase):
|
||||
|
||||
@@ -31,8 +31,9 @@ from markupsafe import escape
|
||||
|
||||
from courseware import grades
|
||||
from courseware.access import has_access, in_preview_mode, _adjust_start_date_for_beta_testers
|
||||
from courseware.access_response import StartDateError
|
||||
from courseware.courses import (
|
||||
get_courses, get_course,
|
||||
get_courses, get_course, get_course_by_id,
|
||||
get_studio_url, get_course_with_access,
|
||||
sort_by_announcement,
|
||||
sort_by_start_date,
|
||||
@@ -60,6 +61,7 @@ from open_ended_grading.views import StaffGradingTab, PeerGradingTab, OpenEndedG
|
||||
from student.models import UserTestGroup, CourseEnrollment
|
||||
from student.views import is_course_blocked
|
||||
from util.cache import cache, cache_if_anonymous
|
||||
from util.date_utils import strftime_localized
|
||||
from xblock.fragment import Fragment
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem
|
||||
@@ -674,9 +676,23 @@ def course_info(request, course_id):
|
||||
Assumes the course_id is in a valid format.
|
||||
"""
|
||||
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_id)
|
||||
|
||||
with modulestore().bulk_operations(course_key):
|
||||
course = get_course_with_access(request.user, 'load', course_key)
|
||||
course = get_course_by_id(course_key, depth=2)
|
||||
access_response = has_access(request.user, 'load', course, course_key)
|
||||
|
||||
if not access_response:
|
||||
|
||||
# The user doesn't have access to the course. If they're
|
||||
# denied permission due to the course not being live yet,
|
||||
# redirect to the dashboard page.
|
||||
if isinstance(access_response, StartDateError):
|
||||
start_date = strftime_localized(course.start, 'SHORT_DATE')
|
||||
params = urllib.urlencode({'notlive': start_date})
|
||||
return redirect('{0}?{1}'.format(reverse('dashboard'), params))
|
||||
# Otherwise, give a 404 to avoid leaking info about access
|
||||
# control.
|
||||
raise Http404("Course not found.")
|
||||
|
||||
staff_access = has_access(request.user, 'staff', course)
|
||||
masquerade, user = setup_masquerade(request, course_key, staff_access, reset_masquerade_data=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user