From 6019971dd418322723c63fa4a346c94f067b7fae Mon Sep 17 00:00:00 2001 From: Zainab Amir Date: Fri, 22 Oct 2021 12:17:06 +0500 Subject: [PATCH] feat: put year of birth behind feature flag (#29007) --- cms/envs/common.py | 3 ++ .../js/student_account/views/AccessView.js | 4 +- .../js/student_account/views/RegisterView.js | 7 ++- lms/static/sass/views/_login-register.scss | 8 ++++ .../djangoapps/user_authn/views/login_form.py | 1 + .../djangoapps/user_authn/views/register.py | 5 +- .../user_authn/views/registration_form.py | 3 ++ .../user_authn/views/tests/test_register.py | 46 ++++++++++++++++++- 8 files changed, 72 insertions(+), 5 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 974e99370a..c98a03abd0 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -474,6 +474,9 @@ FEATURES = { 'ENABLE_V2_CERT_DISPLAY_SETTINGS': False, } +# VAN-754 - Year of birth field put behind a flag to make it available for openedX. +COLLECT_YEAR_OF_BIRTH = True + ENABLE_JASMINE = False # List of logout URIs for each IDA that the learner should be logged out of when they logout of the LMS. Only applies to diff --git a/lms/static/js/student_account/views/AccessView.js b/lms/static/js/student_account/views/AccessView.js index d59f1a86c6..4ae7e9ca6b 100644 --- a/lms/static/js/student_account/views/AccessView.js +++ b/lms/static/js/student_account/views/AccessView.js @@ -82,6 +82,7 @@ this.isEnterpriseEnable = options.is_enterprise_enable || false; this.isAccountRecoveryFeatureEnabled = options.is_account_recovery_feature_enabled || false; this.is_require_third_party_auth_enabled = options.is_require_third_party_auth_enabled || false; + this.collect_year_of_birth = options.collect_year_of_birth; // The login view listens for 'sync' events from the reset model this.resetModel = new PasswordResetModel({}, { @@ -207,7 +208,8 @@ thirdPartyAuth: this.thirdPartyAuth, platformName: this.platformName, hideAuthWarnings: this.hideAuthWarnings, - is_require_third_party_auth_enabled: this.is_require_third_party_auth_enabled + is_require_third_party_auth_enabled: this.is_require_third_party_auth_enabled, + collectYearOfBirth: this.collect_year_of_birth, }); // Listen for 'auth-complete' event so we can enroll/redirect the user appropriately. diff --git a/lms/static/js/student_account/views/RegisterView.js b/lms/static/js/student_account/views/RegisterView.js index db5f6ae855..654a72a5cf 100644 --- a/lms/static/js/student_account/views/RegisterView.js +++ b/lms/static/js/student_account/views/RegisterView.js @@ -64,7 +64,8 @@ this.autoRegisterWelcomeMessage = data.thirdPartyAuth.autoRegisterWelcomeMessage || ''; this.registerFormSubmitButtonText = data.thirdPartyAuth.registerFormSubmitButtonText || _('Create Account'); - this.is_require_third_party_auth_enabled = data.is_require_third_party_auth_enabled || false; + this.is_require_third_party_auth_enabled = data.is_require_third_party_auth_enabled; + this.collectYearOfBirth = data.collectYearOfBirth; this.listenTo(this.model, 'sync', this.saveSuccess); this.listenTo(this.model, 'validation', this.renderLiveValidations); @@ -128,7 +129,9 @@ html = this.renderFields(requiredFields, 'required-fields'); - html.push.apply(html, this.renderFields(optionalFields, 'optional-fields')); + html.push.apply(html, this.renderFields( + optionalFields, `optional-fields ${this.collectYearOfBirth ? '' : 'full-length-fields'}` + )); this.render(html.join('')); }, diff --git a/lms/static/sass/views/_login-register.scss b/lms/static/sass/views/_login-register.scss index bee878af71..93eeee998c 100644 --- a/lms/static/sass/views/_login-register.scss +++ b/lms/static/sass/views/_login-register.scss @@ -508,6 +508,14 @@ ul.fa-ul{ /** FROM _accounts.scss - end **/ } + + .optional-fields { + &.full-length-fields { + .select-gender { + width: 100%; + } + } + } .input-block { width: 100%; border-color: $gray; diff --git a/openedx/core/djangoapps/user_authn/views/login_form.py b/openedx/core/djangoapps/user_authn/views/login_form.py index 8811f3e7ab..aea0a794b3 100644 --- a/openedx/core/djangoapps/user_authn/views/login_form.py +++ b/openedx/core/djangoapps/user_authn/views/login_form.py @@ -262,6 +262,7 @@ def login_and_registration_form(request, initial_mode="login"): 'enterprise_slug_login_url': get_enterprise_slug_login_url(), 'is_enterprise_enable': enterprise_enabled(), 'is_require_third_party_auth_enabled': is_require_third_party_auth_enabled(), + 'collect_year_of_birth': settings.COLLECT_YEAR_OF_BIRTH, }, 'login_redirect_url': redirect_to, # This gets added to the query string of the "Sign In" button in header 'responsive': True, diff --git a/openedx/core/djangoapps/user_authn/views/register.py b/openedx/core/djangoapps/user_authn/views/register.py index 2416e1db80..6653f9ee6c 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -122,7 +122,7 @@ REAL_IP_KEY = 'openedx.core.djangoapps.util.ratelimit.real_ip' @transaction.non_atomic_requests -def create_account_with_params(request, params): +def create_account_with_params(request, params): # pylint: disable=too-many-statements """ Given a request and a dict of parameters (which may or may not have come from the request), create an account for the requesting user, including @@ -169,6 +169,9 @@ def create_account_with_params(request, params): if 'confirm_email' in extra_fields: del extra_fields['confirm_email'] + if not settings.COLLECT_YEAR_OF_BIRTH and 'year_of_birth' in params: + params['year_of_birth'] = '' + # registration via third party (Google, Facebook) using mobile application # doesn't use social auth pipeline (no redirect uri(s) etc involved). # In this case all related info (required for account linking) diff --git a/openedx/core/djangoapps/user_authn/views/registration_form.py b/openedx/core/djangoapps/user_authn/views/registration_form.py index afc7bebb81..84e3df02ef 100644 --- a/openedx/core/djangoapps/user_authn/views/registration_form.py +++ b/openedx/core/djangoapps/user_authn/views/registration_form.py @@ -336,6 +336,9 @@ class RegistrationFormFactory: def __init__(self): + if not settings.COLLECT_YEAR_OF_BIRTH and 'year_of_birth' in self.EXTRA_FIELDS: + self.EXTRA_FIELDS.remove('year_of_birth') + # Backwards compatibility: Honor code is required by default, unless # explicitly set to "optional" in Django settings. self._extra_fields_setting = copy.deepcopy(configuration_helpers.get_value('REGISTRATION_EXTRA_FIELDS')) 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 0f5173f736..fa991d33a7 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -1894,7 +1894,6 @@ class RegistrationViewTestV1( class RegistrationViewTestV2(RegistrationViewTestV1): """ Test for registration api V2 - """ # pylint: disable=test-inherits-tests @@ -2062,6 +2061,51 @@ class RegistrationViewTestV2(RegistrationViewTestV1): "favorite_movie", ] + @override_settings( + COLLECT_YEAR_OF_BIRTH=False, + REGISTRATION_EXTRA_FIELDS={ + "level_of_education": "optional", + "gender": "optional", + "year_of_birth": "optional", + "mailing_address": "optional", + "goals": "optional", + "city": "optional", + "state": "optional", + "country": "required", + "honor_code": "required", + "confirm_email": "required", + }, + REGISTRATION_FIELD_ORDER=None, + REGISTRATION_EXTENSION_FORM='openedx.core.djangoapps.user_api.tests.test_helpers.TestCaseForm', + ) + def test_year_of_birth_field_with_feature_flag(self): + """ + Test that year of birth is not returned when COLLECT_YEAR_OF_BIRTH is + set to False. + """ + response = self.client.get(self.url) + self.assertHttpOK(response) + + # Verify that all fields render in the correct order + form_desc = json.loads(response.content.decode('utf-8')) + field_names = [field["name"] for field in form_desc["fields"]] + assert field_names == [ + "email", + "name", + "username", + "password", + "confirm_email", + "city", + "state", + "country", + "gender", + "level_of_education", + "mailing_address", + "goals", + "honor_code", + "favorite_movie", + ] + def test_registration_form_confirm_email(self): self._assert_reg_field( {"confirm_email": "required"},