Handle anonymous and unenrolled users on the new course home page

LEARNER-1696
This commit is contained in:
Andy Armstrong
2017-07-03 13:16:22 -04:00
committed by Diana Huang
parent fade4a10af
commit 13854fb8ab
4 changed files with 41 additions and 10 deletions

View File

@@ -3,13 +3,19 @@ Views for the course home page.
"""
from django.core.context_processors import csrf
from django.core.urlresolvers import reverse
from django.template.loader import render_to_string
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_control
from django.views.decorators.csrf import ensure_csrf_cookie
from courseware.access import has_access
from courseware.courses import get_course_info_section, get_course_with_access
from courseware.courses import (
can_self_enroll_in_course,
get_course_info_section,
get_course_with_access,
)
from lms.djangoapps.courseware.exceptions import CourseAccessRedirect
from lms.djangoapps.courseware.views.views import CourseTabView
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
@@ -117,6 +123,12 @@ class CourseHomeFragmentView(EdxFragmentView):
course_sock_fragment = CourseSockFragmentView().render_to_fragment(request, course=course, **kwargs)
has_visited_course, resume_course_url = self._get_resume_course_info(request, course_id)
else:
# Redirect the user to the dashboard if they are not enrolled and
# this is a course that does not support direct enrollment.
if not can_self_enroll_in_course(course_key):
raise CourseAccessRedirect(reverse('dashboard'))
# Set all the fragments
outline_fragment = None
welcome_message_fragment = None
course_sock_fragment = None
@@ -129,6 +141,9 @@ class CourseHomeFragmentView(EdxFragmentView):
# Get the course tools enabled for this user and course
course_tools = CourseToolsPluginManager.get_enabled_course_tools(request, course_key)
# Get the course tools enabled for this user and course
course_tools = CourseToolsPluginManager.get_enabled_course_tools(request, course_key)
# Render the course home fragment
context = {
'request': request,