From 5e41a34dd1c98e0113bb1fc7d32cf494cde913c1 Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Wed, 3 Dec 2014 17:01:21 -0500 Subject: [PATCH] Refrain from setting email opt-in preference when checkbox is missing --- .../student/tests/test_enrollment.py | 10 +++- common/djangoapps/student/views.py | 6 ++- .../courseware/mktg_course_about.html | 49 ++++++++++++------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/common/djangoapps/student/tests/test_enrollment.py b/common/djangoapps/student/tests/test_enrollment.py index b616f40f1c..9e92c046c4 100644 --- a/common/djangoapps/student/tests/test_enrollment.py +++ b/common/djangoapps/student/tests/test_enrollment.py @@ -110,10 +110,13 @@ class EnrollmentTest(ModuleStoreTestCase): @ddt.data( ([], 'true'), ([], 'false'), + ([], None), (['honor', 'verified'], 'true'), (['honor', 'verified'], 'false'), + (['honor', 'verified'], None), (['professional'], 'true'), (['professional'], 'false'), + (['professional'], None), ) @ddt.unpack def test_enroll_with_email_opt_in(self, course_modes, email_opt_in, mock_update_email_opt_in): @@ -129,8 +132,11 @@ class EnrollmentTest(ModuleStoreTestCase): self._change_enrollment('enroll', email_opt_in=email_opt_in) # Verify that the profile API has been called as expected - opt_in = email_opt_in == 'true' - mock_update_email_opt_in.assert_called_once_with(self.USERNAME, self.course.org, opt_in) + if email_opt_in is not None: + opt_in = email_opt_in == 'true' + mock_update_email_opt_in.assert_called_once_with(self.USERNAME, self.course.org, opt_in) + else: + self.assertFalse(mock_update_email_opt_in.called) def test_user_not_authenticated(self): # Log out, so we're no longer authenticated diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index d995a72001..43986e320f 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -776,8 +776,10 @@ def try_change_enrollment(request): def _update_email_opt_in(request, username, org): """Helper function used to hit the profile API if email opt-in is enabled.""" - email_opt_in = request.POST.get('email_opt_in') == 'true' - profile_api.update_email_opt_in(username, org, email_opt_in) + email_opt_in = request.POST.get('email_opt_in') + if email_opt_in is not None: + email_opt_in_boolean = email_opt_in == 'true' + profile_api.update_email_opt_in(username, org, email_opt_in_boolean) @require_POST diff --git a/lms/templates/courseware/mktg_course_about.html b/lms/templates/courseware/mktg_course_about.html index 3186dd8e81..6a0bac8859 100644 --- a/lms/templates/courseware/mktg_course_about.html +++ b/lms/templates/courseware/mktg_course_about.html @@ -11,19 +11,30 @@ <%block name="bodyclass">view-iframe-content view-partial-mktgregister - <%block name="js_extra">