From acf5add774802efb090efa645f0375e8de63571a Mon Sep 17 00:00:00 2001 From: Zainab Amir Date: Tue, 7 Dec 2021 17:16:28 +0500 Subject: [PATCH] feat: add marketing email option on registration (#29397) --- cms/envs/common.py | 1 + ...151113_1443.cpython-38.pyc.140168653634528 | 0 .../js/student_account/views/RegisterView.js | 2 +- lms/static/sass/views/_login-register.scss | 6 +++++ .../student_account/form_field.underscore | 1 + .../djangoapps/user_authn/views/register.py | 2 +- .../user_authn/views/registration_form.py | 25 +++++++++++++++++++ .../user_authn/views/tests/test_register.py | 15 +++++++++++ 8 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 lms/djangoapps/verify_student/migrations/__pycache__/0003_auto_20151113_1443.cpython-38.pyc.140168653634528 diff --git a/cms/envs/common.py b/cms/envs/common.py index d5e912651a..23e3073c00 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -2443,6 +2443,7 @@ REGISTRATION_EXTRA_FIELDS = { 'terms_of_service': 'hidden', 'city': 'hidden', 'country': 'hidden', + 'marketing_emails_opt_in': 'hidden', } EDXAPP_PARSE_KEYS = {} diff --git a/lms/djangoapps/verify_student/migrations/__pycache__/0003_auto_20151113_1443.cpython-38.pyc.140168653634528 b/lms/djangoapps/verify_student/migrations/__pycache__/0003_auto_20151113_1443.cpython-38.pyc.140168653634528 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lms/static/js/student_account/views/RegisterView.js b/lms/static/js/student_account/views/RegisterView.js index 5de123c2b0..53acb19f2c 100644 --- a/lms/static/js/student_account/views/RegisterView.js +++ b/lms/static/js/student_account/views/RegisterView.js @@ -86,7 +86,7 @@ html.push(HtmlUtils.template(fieldTpl)($.extend(fields[i], { form: this.formType, requiredStr: this.requiredStr, - optionalStr: this.optionalStr, + optionalStr: fields[i].name === 'marketing_emails_opt_in' ? '' : this.optionalStr, supplementalText: fields[i].supplementalText || '', supplementalLink: fields[i].supplementalLink || '' }))); diff --git a/lms/static/sass/views/_login-register.scss b/lms/static/sass/views/_login-register.scss index 93eeee998c..f2db31c28e 100644 --- a/lms/static/sass/views/_login-register.scss +++ b/lms/static/sass/views/_login-register.scss @@ -320,6 +320,12 @@ ul.fa-ul{ width: calc(50% - 10px); } + &.checkbox-marketing_emails_opt_in { + .label-text { + font-size: small !important; + } + } + .label-text-small { font-size: small; } diff --git a/lms/templates/student_account/form_field.underscore b/lms/templates/student_account/form_field.underscore index f879ba4600..67c945e5f0 100644 --- a/lms/templates/student_account/form_field.underscore +++ b/lms/templates/student_account/form_field.underscore @@ -101,6 +101,7 @@ <% if ( restrictions.max_length && type !== 'password' ) { %> maxlength="<%- restrictions.max_length %>"<% } %> <% if ( restrictions.readonly ) { %> readonly <% } %> <% if ( required ) { %> required<% } %> + <% if ( defaultValue === true ) { %> checked<% } %> <% if ( typeof errorMessages !== 'undefined' ) { _.each(errorMessages, function( msg, type ) {%> data-errormsg-<%- type %>="<%- msg %>" diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 998c4ef927..c32534908f 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -581,7 +581,7 @@ class RegistrationView(APIView): redirect_url = get_redirect_url_with_host(root_url, redirect_to) response = self._create_response(request, {}, status_code=200, redirect_url=redirect_url) set_logged_in_cookies(request, response, user) - if not user.is_active and settings.SHOW_ACCOUNT_ACTIVATION_CTA and 'marketing_emails_opt_in' not in data: + if not user.is_active and settings.SHOW_ACCOUNT_ACTIVATION_CTA and not settings.MARKETING_EMAILS_OPT_IN: response.set_cookie( settings.SHOW_ACTIVATE_CTA_POPUP_COOKIE_NAME, True, diff --git a/openedx/core/djangoapps/user_authn/views/registration_form.py b/openedx/core/djangoapps/user_authn/views/registration_form.py index 1c96a6bbda..79a66fa554 100644 --- a/openedx/core/djangoapps/user_authn/views/registration_form.py +++ b/openedx/core/djangoapps/user_authn/views/registration_form.py @@ -324,6 +324,7 @@ class RegistrationFormFactory: "terms_of_service", "profession", "specialty", + "marketing_emails_opt_in", ] def _is_field_visible(self, field_name): @@ -350,6 +351,9 @@ class RegistrationFormFactory: self._extra_fields_setting = copy.deepcopy(settings.REGISTRATION_EXTRA_FIELDS) self._extra_fields_setting["honor_code"] = self._extra_fields_setting.get("honor_code", "required") + if settings.MARKETING_EMAILS_OPT_IN: + self._extra_fields_setting['marketing_emails_opt_in'] = 'optional' + # Check that the setting is configured correctly for field_name in self.EXTRA_FIELDS: if self._extra_fields_setting.get(field_name, "hidden") not in ["required", "optional", "hidden"]: @@ -660,6 +664,27 @@ class RegistrationFormFactory: required=required ) + def _add_marketing_emails_opt_in_field(self, form_desc, required=False): + """Add a marketing email checkbox to form description. + Arguments: + form_desc: A form description + Keyword Arguments: + required (bool): Whether this field is required; defaults to False + """ + opt_in_label = _( + 'I agree that {platform_name} may send me marketing messages.').format( + platform_name=configuration_helpers.get_value('PLATFORM_NAME', settings.PLATFORM_NAME), + ) + + form_desc.add_field( + 'marketing_emails_opt_in', + label=opt_in_label, + field_type="checkbox", + exposed=True, + default=True, # the checkbox will automatically be checked; meaning user has opted in + required=required, + ) + def _add_field_with_configurable_select_options(self, field_name, field_label, form_desc, required=False): """Add a field to a form description. If select options are given for this field, it will be a select type diff --git a/openedx/core/djangoapps/user_authn/views/tests/test_register.py b/openedx/core/djangoapps/user_authn/views/tests/test_register.py index b857197098..1d3191db8d 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -962,6 +962,21 @@ class RegistrationViewTestV1( } ) + def test_register_form_marketing_emails_opt_in_field(self): + self._assert_reg_field( + {"marketing_emails_opt_in": "optional"}, + { + "name": "marketing_emails_opt_in", + "type": "checkbox", + "required": False, + "label": 'I agree that {platform_name} may send me marketing messages.'.format( + platform_name=settings.PLATFORM_NAME, + ), + "exposed": True, + "defaultValue": True, + } + ) + def test_register_form_profession_without_profession_options(self): self._assert_reg_field( {"profession": "required"},