feat: put year of birth behind feature flag (#29007)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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'))
|
||||
|
||||
@@ -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"},
|
||||
|
||||
Reference in New Issue
Block a user