From d5ab616ca8f11f70f337f8834580fd7023f9a343 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Thu, 28 Oct 2021 14:12:53 +0500 Subject: [PATCH] feat: COPPA - remove `primary/elementary` option from education (#29147) Remove `primary/elementary` option from education field if COPPA compliance feature flag is enabled. Also, renamed the flag. VAN-762 --- cms/envs/common.py | 11 +++++++++-- lms/envs/common.py | 11 +++++++++-- .../account_settings_factory_spec.js | 4 ++-- lms/static/js/spec/student_account/helpers.js | 4 ++-- lms/static/js/student_account/views/AccessView.js | 4 ++-- lms/static/js/student_account/views/RegisterView.js | 4 ++-- .../views/account_settings_factory.js | 13 +++++++++---- lms/templates/student_account/account_settings.html | 4 ++-- .../djangoapps/user_api/accounts/settings_views.py | 2 +- .../core/djangoapps/user_authn/views/login_form.py | 2 +- .../core/djangoapps/user_authn/views/register.py | 2 +- .../user_authn/views/registration_form.py | 2 +- .../user_authn/views/tests/test_register.py | 6 +++--- 13 files changed, 44 insertions(+), 25 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 1209a50e4d..ae2b65709e 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -474,8 +474,15 @@ 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 +# .. toggle_name: ENABLE_COPPA_COMPLIANCE +# .. toggle_implementation: DjangoSetting +# .. toggle_default: False +# .. toggle_description: When True, inforces COPPA compliance and removes YOB field from registration form and accounnt +# .. settings page. Also hide YOB banner from profile page. +# .. toggle_use_cases: open_edx +# .. toggle_creation_date: 2021-10-27 +# .. toggle_tickets: 'https://openedx.atlassian.net/browse/VAN-622' +ENABLE_COPPA_COMPLIANCE = False ENABLE_JASMINE = False diff --git a/lms/envs/common.py b/lms/envs/common.py index 15e576e734..6d8bbe2bce 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -991,8 +991,15 @@ COURSE_MESSAGE_ALERT_DURATION_IN_DAYS = 14 MARKETING_EMAILS_OPT_IN = False -# VAN-754 - Year of birth field put behind a flag to make it available for OpenedX. -COLLECT_YEAR_OF_BIRTH = True +# .. toggle_name: ENABLE_COPPA_COMPLIANCE +# .. toggle_implementation: DjangoSetting +# .. toggle_default: False +# .. toggle_description: When True, inforces COPPA compliance and removes YOB field from registration form and accounnt +# .. settings page. Also hide YOB banner from profile page. +# .. toggle_use_cases: open_edx +# .. toggle_creation_date: 2021-10-27 +# .. toggle_tickets: 'https://openedx.atlassian.net/browse/VAN-622' +ENABLE_COPPA_COMPLIANCE = False ############################# SET PATH INFORMATION ############################# PROJECT_ROOT = path(__file__).abspath().dirname().dirname() # /edx-platform/lms diff --git a/lms/static/js/spec/student_account/account_settings_factory_spec.js b/lms/static/js/spec/student_account/account_settings_factory_spec.js index 3785c7cf7f..3495af8e05 100644 --- a/lms/static/js/spec/student_account/account_settings_factory_spec.js +++ b/lms/static/js/spec/student_account/account_settings_factory_spec.js @@ -27,7 +27,7 @@ define(['backbone', Helpers.PLATFORM_NAME, Helpers.CONTACT_EMAIL, true, - Helpers.COLLECT_YEAR_OF_BIRTH + Helpers.ENABLE_COPPA_COMPLIANCE ); return context.accountSettingsView; }; @@ -165,7 +165,7 @@ define(['backbone', Helpers.PLATFORM_NAME, Helpers.CONTACT_EMAIL, true, - Helpers.COLLECT_YEAR_OF_BIRTH, + Helpers.ENABLE_COPPA_COMPLIANCE, '', Helpers.SYNC_LEARNER_PROFILE_DATA, diff --git a/lms/static/js/spec/student_account/helpers.js b/lms/static/js/spec/student_account/helpers.js index f1842eb87c..a7989ce628 100644 --- a/lms/static/js/spec/student_account/helpers.js +++ b/lms/static/js/spec/student_account/helpers.js @@ -10,7 +10,7 @@ define(['underscore'], function(_) { var PASSWORD_RESET_SUPPORT_LINK = 'https://support.edx.org/hc/en-us/articles/206212088-What-if-I-did-not-receive-a-password-reset-message-'; // eslint-disable-line max-len var PLATFORM_NAME = 'edX'; var CONTACT_EMAIL = 'info@example.com'; - var COLLECT_YEAR_OF_BIRTH = true; + var ENABLE_COPPA_COMPLIANCE = false; var SYNC_LEARNER_PROFILE_DATA = true; var ENTERPRISE_NAME = 'Test Enterprise'; @@ -222,7 +222,7 @@ define(['underscore'], function(_) { PASSWORD_RESET_SUPPORT_LINK: PASSWORD_RESET_SUPPORT_LINK, PLATFORM_NAME: PLATFORM_NAME, CONTACT_EMAIL: CONTACT_EMAIL, - COLLECT_YEAR_OF_BIRTH: COLLECT_YEAR_OF_BIRTH, + ENABLE_COPPA_COMPLIANCE: ENABLE_COPPA_COMPLIANCE, SYNC_LEARNER_PROFILE_DATA: SYNC_LEARNER_PROFILE_DATA, ENTERPRISE_NAME: ENTERPRISE_NAME, diff --git a/lms/static/js/student_account/views/AccessView.js b/lms/static/js/student_account/views/AccessView.js index 4ae7e9ca6b..7216aa1ce7 100644 --- a/lms/static/js/student_account/views/AccessView.js +++ b/lms/static/js/student_account/views/AccessView.js @@ -82,7 +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; + this.enable_coppa_compliance = options.enable_coppa_compliance; // The login view listens for 'sync' events from the reset model this.resetModel = new PasswordResetModel({}, { @@ -209,7 +209,7 @@ platformName: this.platformName, hideAuthWarnings: this.hideAuthWarnings, is_require_third_party_auth_enabled: this.is_require_third_party_auth_enabled, - collectYearOfBirth: this.collect_year_of_birth, + enableCoppaCompliance: this.enable_coppa_compliance, }); // 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 654a72a5cf..48d5409414 100644 --- a/lms/static/js/student_account/views/RegisterView.js +++ b/lms/static/js/student_account/views/RegisterView.js @@ -65,7 +65,7 @@ this.registerFormSubmitButtonText = data.thirdPartyAuth.registerFormSubmitButtonText || _('Create Account'); this.is_require_third_party_auth_enabled = data.is_require_third_party_auth_enabled; - this.collectYearOfBirth = data.collectYearOfBirth; + this.enableCoppaCompliance = data.enableCoppaCompliance; this.listenTo(this.model, 'sync', this.saveSuccess); this.listenTo(this.model, 'validation', this.renderLiveValidations); @@ -130,7 +130,7 @@ html = this.renderFields(requiredFields, 'required-fields'); html.push.apply(html, this.renderFields( - optionalFields, `optional-fields ${this.collectYearOfBirth ? '' : 'full-length-fields'}` + optionalFields, `optional-fields ${!this.enableCoppaCompliance ? '' : 'full-length-fields'}` )); this.render(html.join('')); diff --git a/lms/static/js/student_account/views/account_settings_factory.js b/lms/static/js/student_account/views/account_settings_factory.js index 1a5e72da03..882f3f693d 100644 --- a/lms/static/js/student_account/views/account_settings_factory.js +++ b/lms/static/js/student_account/views/account_settings_factory.js @@ -22,7 +22,7 @@ platformName, contactEmail, allowEmailChange, - collectYearOfBirth, + enableCoppaCompliance, socialPlatforms, syncLearnerProfileData, enterpriseName, @@ -39,7 +39,7 @@ emailFieldView, secondaryEmailFieldView, socialFields, accountDeletionFields, platformData, aboutSectionMessageType, aboutSectionMessage, fullnameFieldView, countryFieldView, fullNameFieldData, emailFieldData, secondaryEmailFieldData, countryFieldData, additionalFields, - fieldItem, emailFieldViewIndex, focusId, yearOfBirthViewIndex, + fieldItem, emailFieldViewIndex, focusId, yearOfBirthViewIndex, levelOfEducationFieldData, tabIndex = 0; $accountSettingsElement = $('.wrapper-account-settings'); @@ -135,6 +135,11 @@ }; } + levelOfEducationFieldData = fieldsData.level_of_education.options; + if (enableCoppaCompliance) { + levelOfEducationFieldData = levelOfEducationFieldData.filter(option => option[0] !== 'el'); + } + aboutSectionsData = [ { title: gettext('Basic Account Information'), @@ -212,7 +217,7 @@ model: userAccountModel, title: gettext('Education Completed'), valueAttribute: 'level_of_education', - options: fieldsData.level_of_education.options, + options: levelOfEducationFieldData, persistChanges: true }) }, @@ -247,7 +252,7 @@ } ]; - if (!collectYearOfBirth){ + if (enableCoppaCompliance){ yearOfBirthViewIndex = aboutSectionsData[1]['fields'].findIndex(function (field) { return field['view']['options']['valueAttribute']=== 'year_of_birth'; }); diff --git a/lms/templates/student_account/account_settings.html b/lms/templates/student_account/account_settings.html index 4dbbc4ed04..4bdca0a81b 100644 --- a/lms/templates/student_account/account_settings.html +++ b/lms/templates/student_account/account_settings.html @@ -48,7 +48,7 @@ from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_f extendedProfileFields = ${ extended_profile_fields | n, dump_js_escaped_json }, displayAccountDeletion = ${ enable_account_deletion | n, dump_js_escaped_json}; isSecondaryEmailFeatureEnabled = ${ bool(is_secondary_email_feature_enabled()) | n, dump_js_escaped_json }, - collectYearOfBirth = ${ bool(collect_year_of_birth) | n, dump_js_escaped_json }, + enableCoppaCompliance = ${ bool(enable_coppa_compliance) | n, dump_js_escaped_json }, AccountSettingsFactory( fieldsData, @@ -62,7 +62,7 @@ from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_f platformName, contactEmail, allowEmailChange, - collectYearOfBirth, + enableCoppaCompliance, socialPlatforms, syncLearnerProfileData, diff --git a/openedx/core/djangoapps/user_api/accounts/settings_views.py b/openedx/core/djangoapps/user_api/accounts/settings_views.py index 398ac3eb83..92bb6a6ae9 100644 --- a/openedx/core/djangoapps/user_api/accounts/settings_views.py +++ b/openedx/core/djangoapps/user_api/accounts/settings_views.py @@ -144,7 +144,7 @@ def account_settings_context(request): ), 'extended_profile_fields': _get_extended_profile_fields(), 'beta_language': beta_language, - 'collect_year_of_birth': settings.COLLECT_YEAR_OF_BIRTH, + 'enable_coppa_compliance': settings.ENABLE_COPPA_COMPLIANCE, } enterprise_customer = enterprise_customer_for_request(request) diff --git a/openedx/core/djangoapps/user_authn/views/login_form.py b/openedx/core/djangoapps/user_authn/views/login_form.py index 94a52354be..4bd2fab23b 100644 --- a/openedx/core/djangoapps/user_authn/views/login_form.py +++ b/openedx/core/djangoapps/user_authn/views/login_form.py @@ -262,7 +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, + 'enable_coppa_compliance': settings.ENABLE_COPPA_COMPLIANCE, }, '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 2f998d74d3..387ae8bd00 100644 --- a/openedx/core/djangoapps/user_authn/views/register.py +++ b/openedx/core/djangoapps/user_authn/views/register.py @@ -170,7 +170,7 @@ def create_account_with_params(request, params): # pylint: disable=too-many-sta if 'confirm_email' in extra_fields: del extra_fields['confirm_email'] - if not settings.COLLECT_YEAR_OF_BIRTH and 'year_of_birth' in params: + if settings.ENABLE_COPPA_COMPLIANCE and 'year_of_birth' in params: params['year_of_birth'] = '' # registration via third party (Google, Facebook) using mobile application diff --git a/openedx/core/djangoapps/user_authn/views/registration_form.py b/openedx/core/djangoapps/user_authn/views/registration_form.py index f0bf8eb77b..8306942026 100644 --- a/openedx/core/djangoapps/user_authn/views/registration_form.py +++ b/openedx/core/djangoapps/user_authn/views/registration_form.py @@ -336,7 +336,7 @@ class RegistrationFormFactory: def __init__(self): - if not settings.COLLECT_YEAR_OF_BIRTH and 'year_of_birth' in self.EXTRA_FIELDS: + if settings.ENABLE_COPPA_COMPLIANCE and 'year_of_birth' in self.EXTRA_FIELDS: self.EXTRA_FIELDS.remove('year_of_birth') # Backwards compatibility: Honor code is required by default, unless 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 fa991d33a7..daf9e991d1 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -2062,7 +2062,7 @@ class RegistrationViewTestV2(RegistrationViewTestV1): ] @override_settings( - COLLECT_YEAR_OF_BIRTH=False, + ENABLE_COPPA_COMPLIANCE=True, REGISTRATION_EXTRA_FIELDS={ "level_of_education": "optional", "gender": "optional", @@ -2080,8 +2080,8 @@ class RegistrationViewTestV2(RegistrationViewTestV1): ) 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. + Test that year of birth is not returned when ENABLE_COPPA_COMPLIANCE is + set to True. """ response = self.client.get(self.url) self.assertHttpOK(response)