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

@@ -131,6 +131,19 @@ def check_course_access(course, user, action, check_if_enrolled=False):
raise CourseAccessRedirect(reverse('about_course', args=[unicode(course.id)]))
def can_self_enroll_in_course(course_key):
"""
Returns True if the user can enroll themselves in a course.
Note: an example of a course that a user cannot enroll in directly
is a CCX course. For such courses, a user can only be enrolled by
a CCX coach.
"""
if hasattr(course_key, 'ccx'):
return False
return True
def find_file(filesystem, dirs, filename):
"""
Looks for a filename in a list of dirs on a filesystem, in the specified order.

View File

@@ -46,6 +46,7 @@ from courseware.access import has_access, has_ccx_coach_role
from courseware.access_response import StartDateError
from courseware.access_utils import in_preview_mode, is_course_open_for_learner
from courseware.courses import (
can_self_enroll_in_course,
get_course,
get_course_by_id,
get_course_overview_with_access,
@@ -287,10 +288,10 @@ def course_info(request, course_id):
# if user is not enrolled in a course then app will show enroll/get register link inside course info page.
user_is_enrolled = CourseEnrollment.is_enrolled(user, course.id)
show_enroll_banner = request.user.is_authenticated() and not user_is_enrolled
if show_enroll_banner and hasattr(course_key, 'ccx'):
# if course is CCX and user is not enrolled/registered then do not let him open course direct via link for
# self registration. Because only CCX coach can register/enroll a student. If un-enrolled user try
# to access CCX redirect him to dashboard.
# If the user is not enrolled but this is a course that does not support
# direct enrollment then redirect them to the dashboard.
if not user_is_enrolled and not can_self_enroll_in_course(course_key):
return redirect(reverse('dashboard'))
# Redirect the user if they are not yet allowed to view this course
@@ -351,6 +352,7 @@ def course_info(request, course_id):
# TODO: (Experimental Code). See https://openedx.atlassian.net/wiki/display/RET/2.+In-course+Verification+Prompts
'upgrade_link': check_and_get_upgrade_link(request, user, course.id),
'upgrade_price': get_cosmetic_verified_display_price(course),
'course_tools': course_tools,
# ENDTODO
}
@@ -681,11 +683,9 @@ def course_about(request, course_id):
"""
course_key = CourseKey.from_string(course_id)
if hasattr(course_key, 'ccx'):
# if un-enrolled/non-registered user try to access CCX (direct for registration)
# then do not show him about page to avoid self registration.
# Note: About page will only be shown to user who is not register. So that he can register. But for
# CCX only CCX coach can enroll students.
# If a user is not able to enroll in a course then redirect
# them away from the about page to the dashboard.
if not can_self_enroll_in_course(course_key):
return redirect(reverse('dashboard'))
with modulestore().bulk_operations(course_key):