From f22c193dc4fa81c8fccbbb6ed7a860fa6da0634d Mon Sep 17 00:00:00 2001 From: Arjun Singh Yadav Date: Wed, 31 Mar 2021 18:06:41 +0530 Subject: [PATCH] BB-3954 Add toggle for enrollment behavior Adds toggle REDIRECT_UNAUTHENTICATED_USER_TO_LOGIN_ON_ENROLL for enrollment behaviour for unauthenticated user. If true, the user will be redirected to 'signin_user' route. --- lms/envs/common.py | 4 ++++ lms/templates/courseware/course_about.html | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lms/envs/common.py b/lms/envs/common.py index e2993a4eadda..78f06a0e7453 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -702,6 +702,10 @@ # e.g. COURSE_BLOCKS_API_EXTRA_FIELDS = [ ('course', 'other_course_settings'), ("problem", "weight") ] COURSE_BLOCKS_API_EXTRA_FIELDS = [] +# Setting to redirect unauthenticated users to the login page when enrolling from the course about +# page instead of showing an error message. After successful login redirects them back to the course about page. +REDIRECT_UNAUTHENTICATED_USER_TO_LOGIN_ON_ENROLL = False + # Settings for the course reviews tool template and identification key, set either to None to disable course reviews COURSE_REVIEWS_TOOL_PROVIDER_FRAGMENT_NAME = 'coursetalk-reviews-fragment.html' COURSE_REVIEWS_TOOL_PROVIDER_PLATFORM_KEY = 'edx' diff --git a/lms/templates/courseware/course_about.html b/lms/templates/courseware/course_about.html index c09acc06d848..3579e4886a3c 100644 --- a/lms/templates/courseware/course_about.html +++ b/lms/templates/courseware/course_about.html @@ -40,9 +40,13 @@ location.href = xhr.responseText; } } else if (xhr.status == 403) { - $('#register_error').text( - (xhr.responseText ? xhr.responseText : "${_("An error has occurred. Please ensure that you are logged in to enroll.") | n, js_escaped_string}") - ).css("display", "block"); + %if settings.REDIRECT_UNAUTHENTICATED_USER_TO_LOGIN_ON_ENROLL: + location.replace("${reverse('signin_user') | n, js_escaped_string}?next=${request.path | u}"); + %else: + $('#register_error').text( + (xhr.responseText ? xhr.responseText : "${_("An error has occurred. Please ensure that you are logged in to enroll.") | n, js_escaped_string}") + ).css("display", "block"); + %endif } else { $('#register_error').text( (xhr.responseText ? xhr.responseText : "${_("An error occurred. Please try again later.") | n, js_escaped_string}")