feat: add marketing email option on registration (#29397)

This commit is contained in:
Zainab Amir
2021-12-07 17:16:28 +05:00
committed by GitHub
parent 5f77890c58
commit acf5add774
8 changed files with 50 additions and 2 deletions

View File

@@ -2443,6 +2443,7 @@ REGISTRATION_EXTRA_FIELDS = {
'terms_of_service': 'hidden',
'city': 'hidden',
'country': 'hidden',
'marketing_emails_opt_in': 'hidden',
}
EDXAPP_PARSE_KEYS = {}

View File

@@ -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 || ''
})));

View File

@@ -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;
}

View File

@@ -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 %>"

View File

@@ -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,

View File

@@ -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

View File

@@ -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"},