WIP: Remove misleading copy for Master's-only courses' course pages'

Logged out learners shouldn't be lead to believe they'll be able to
enroll themselves into such courses, which we're worried they may've
read into the existing copy

JIRA:EDUCATOR-4158
This commit is contained in:
Matt Hughes
2019-04-19 10:30:24 -04:00
parent e99c3852b3
commit 1070ba0236
3 changed files with 70 additions and 21 deletions

View File

@@ -2517,9 +2517,39 @@ class TestIndexView(ModuleStoreTestCase):
self.assertIn('xblock-student_view-html', response.content)
self.assertIn('xblock-student_view-video', response.content)
@patch('courseware.views.views.CourseTabView.course_open_for_learner_enrollment')
@patch('openedx.core.djangoapps.util.user_messages.PageLevelMessages.register_warning_message')
def test_courseware_messages_differentiate_for_anonymous_users(
self, patch_register_warning_message, patch_course_open_for_learner_enrollment
):
"""
Tests that the anonymous user case for the
register_user_access_warning_messages returns different
messaging based on the possibility of enrollment
"""
course = CourseFactory()
user = self.create_user_for_course(course, CourseUserType.ANONYMOUS)
request = RequestFactory().get('/')
request.user = user
patch_course_open_for_learner_enrollment.return_value = False
views.CourseTabView.register_user_access_warning_messages(request, course)
open_for_enrollment_message = patch_register_warning_message.mock_calls[0][1][1]
patch_register_warning_message.reset_mock()
patch_course_open_for_learner_enrollment.return_value = True
views.CourseTabView.register_user_access_warning_messages(request, course)
closed_to_enrollment_message = patch_register_warning_message.mock_calls[0][1][1]
assert open_for_enrollment_message != closed_to_enrollment_message
@patch('openedx.core.djangoapps.util.user_messages.PageLevelMessages.register_warning_message')
def test_courseware_messages_masters_only(self, patch_register_warning_message):
with patch('courseware.views.views.CourseTabView.should_show_enroll_button') as patch_should_show_enroll_button:
with patch(
'courseware.views.views.CourseTabView.course_open_for_learner_enrollment'
) as patch_course_open_for_learner_enrollment:
course = CourseFactory()
user = self.create_user_for_course(course, CourseUserType.UNENROLLED)
@@ -2528,7 +2558,7 @@ class TestIndexView(ModuleStoreTestCase):
button_html = '<button class="enroll-btn btn-link">Enroll now</button>'
patch_should_show_enroll_button.return_value = False
patch_course_open_for_learner_enrollment.return_value = False
views.CourseTabView.register_user_access_warning_messages(request, course)
# pull message out of the calls to the mock so that
# we can make finer grained assertions than mock provides
@@ -2537,7 +2567,7 @@ class TestIndexView(ModuleStoreTestCase):
patch_register_warning_message.reset_mock()
patch_should_show_enroll_button.return_value = True
patch_course_open_for_learner_enrollment.return_value = True
views.CourseTabView.register_user_access_warning_messages(request, course)
# pull message out of the calls to the mock so that
# we can make finer grained assertions than mock provides
@@ -2565,7 +2595,10 @@ class TestIndexView(ModuleStoreTestCase):
patch_is_masters_only.return_value = is_masters_only
course.invitation_only = invitation_only
self.assertEqual(views.CourseTabView.should_show_enroll_button(course), expected_should_show_enroll_button)
self.assertEqual(
views.CourseTabView.course_open_for_learner_enrollment(course),
expected_should_show_enroll_button
)
@ddt.ddt

View File

@@ -535,23 +535,38 @@ class CourseTabView(EdxFragmentView):
allow_anonymous = allow_public_access(course, [COURSE_VISIBILITY_PUBLIC])
if request.user.is_anonymous and not allow_anonymous:
PageLevelMessages.register_warning_message(
request,
Text(_(u"To see course content, {sign_in_link} or {register_link}.")).format(
sign_in_link=HTML(u'<a href="/login?next={current_url}">{sign_in_label}</a>').format(
sign_in_label=_("sign in"),
current_url=urlquote_plus(request.path),
),
register_link=HTML(u'<a href="/register?next={current_url}">{register_label}</a>').format(
register_label=_("register"),
current_url=urlquote_plus(request.path),
),
if CourseTabView.course_open_for_learner_enrollment(course):
PageLevelMessages.register_warning_message(
request,
Text(_(u"To see course content, {sign_in_link} or {register_link}.")).format(
sign_in_link=HTML(u'<a href="/login?next={current_url}">{sign_in_label}</a>').format(
sign_in_label=_("sign in"),
current_url=urlquote_plus(request.path),
),
register_link=HTML(u'<a href="/register?next={current_url}">{register_label}</a>').format(
register_label=_("register"),
current_url=urlquote_plus(request.path),
),
)
)
else:
PageLevelMessages.register_warning_message(
request,
Text(_(u"{sign_in_link} or {register_link}.")).format(
sign_in_link=HTML(u'<a href="/login?next={current_url}">{sign_in_label}</a>').format(
sign_in_label=_("Sign in"),
current_url=urlquote_plus(request.path),
),
register_link=HTML(u'<a href="/register?next={current_url}">{register_label}</a>').format(
register_label=_("register"),
current_url=urlquote_plus(request.path),
),
)
)
)
else:
if not CourseEnrollment.is_enrolled(request.user, course.id) and not allow_anonymous:
# Only show enroll button if course is open for enrollment.
if CourseTabView.should_show_enroll_button(course):
if CourseTabView.course_open_for_learner_enrollment(course):
enroll_message = _(u'You must be enrolled in the course to see course content. \
{enroll_link_start}Enroll now{enroll_link_end}.')
PageLevelMessages.register_warning_message(
@@ -568,7 +583,7 @@ class CourseTabView(EdxFragmentView):
)
@staticmethod
def should_show_enroll_button(course):
def course_open_for_learner_enrollment(course):
return (course_open_for_self_enrollment(course.id)
and not course.invitation_only
and not CourseMode.is_masters_only(course.id))

View File

@@ -112,11 +112,12 @@ def _register_course_home_messages(request, course, user_access, course_start_da
allow_anonymous = allow_public_access(course, [COURSE_VISIBILITY_PUBLIC])
if user_access['is_anonymous'] and not allow_anonymous:
sign_in_or_register_text = (_(u'{sign_in_link} or {register_link} and then enroll in this course.')
if not CourseMode.is_masters_only(course.id)
else _(u'{sign_in_link} or {register_link}.'))
CourseHomeMessages.register_info_message(
request,
Text(_(
u'{sign_in_link} or {register_link} and then enroll in this course.'
)).format(
Text(sign_in_or_register_text).format(
sign_in_link=HTML(u'<a href="/login?next={current_url}">{sign_in_label}</a>').format(
sign_in_label=_('Sign in'),
current_url=urlquote_plus(request.path),