From 31e0f794113c9da565fd18b0c88778bfda12d314 Mon Sep 17 00:00:00 2001 From: kingoftech-v01 Date: Fri, 10 Apr 2026 03:17:45 +0000 Subject: [PATCH] fix(user_authn): expose country field by default so Profile MFE can list countries The default for REGISTRATION_EXTRA_FIELDS['country'] was 'hidden', which caused the registration form API to exclude the country field and its options list. The Profile MFE depends on this API to render its country dropdown, so the dropdown showed no options after the Ulmo upgrade. Change the default to 'optional'. Operators who do not want the country field on the registration form can still override it to 'hidden' via site configuration or YAML env config. Closes #38195 --- .../user_authn/views/tests/test_register.py | 62 +++++++++++++++++++ openedx/envs/common.py | 6 +- 2 files changed, 67 insertions(+), 1 deletion(-) 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 2f336826b2b5..76e0cc820efa 100644 --- a/openedx/core/djangoapps/user_authn/views/tests/test_register.py +++ b/openedx/core/djangoapps/user_authn/views/tests/test_register.py @@ -1817,6 +1817,68 @@ def test_country_overrides(self): self.assertContains(response, 'Kosovo') + def test_unit_country_default_is_optional(self): + """ + Unit test for Bug #38195. + + The platform default for REGISTRATION_EXTRA_FIELDS['country'] must be + 'optional' so the country list is exposed via the registration form + API. The Profile MFE depends on this API to render its country + dropdown. + """ + assert settings.REGISTRATION_EXTRA_FIELDS.get('country') == 'optional' + + def test_integration_country_field_exposed_by_default(self): + """ + Integration test for Bug #38195. + + With default settings, the registration form API response must include + the country field populated with its options list, so consumers like + the Profile MFE can render a country dropdown. + """ + response = self.client.get(self.url) + self.assertHttpOK(response) + form_desc = json.loads(response.content.decode('utf-8')) + field_names = [field['name'] for field in form_desc['fields']] + assert 'country' in field_names, \ + "country field must be exposed by default so Profile MFE gets the list" + + country_field = next(f for f in form_desc['fields'] if f['name'] == 'country') + assert country_field['type'] == 'select' + assert len(country_field['options']) > 0, \ + "country field must ship with the full list of country options" + + def test_bug_38195_regression_profile_mfe_gets_country_options(self): + """ + Regression test for Bug #38195. + + Before the fix, the default value of REGISTRATION_EXTRA_FIELDS['country'] + was 'hidden', which caused RegistrationFormFactory._is_field_visible + to exclude the country field entirely from the registration form API + response. The Profile MFE, which consumes this API to get the country + list, had no country options to display. + + This test hits the same API endpoint the Profile MFE uses and + verifies the country options are present in the response payload. + """ + response = self.client.get(self.url) + self.assertHttpOK(response) + self.assertContains(response, 'country') + self.assertContains(response, 'Kosovo') + + @override_settings(REGISTRATION_EXTRA_FIELDS={"country": "hidden"}) + def test_operator_can_still_hide_country(self): + """ + Ensures the default change does not remove the operator's ability to + hide the country field via override. Bug #38195. + """ + response = self.client.get(self.url) + self.assertHttpOK(response) + form_desc = json.loads(response.content.decode('utf-8')) + field_names = [field['name'] for field in form_desc['fields']] + assert 'country' not in field_names, \ + "operator override to 'hidden' must still remove the country field" + def test_password_with_spaces(self): """Test that spaces are stripped correctly from password while creating an account.""" unstripped_password = self.PASSWORD + ' ' diff --git a/openedx/envs/common.py b/openedx/envs/common.py index c7ede8e98481..a34da631b061 100644 --- a/openedx/envs/common.py +++ b/openedx/envs/common.py @@ -1686,7 +1686,11 @@ def add_optional_apps(optional_apps, installed_apps): 'honor_code': 'required', 'terms_of_service': 'hidden', 'city': 'hidden', - 'country': 'hidden', + # 'country' defaults to 'optional' so the country list is exposed via the + # registration form API, which the Profile MFE relies on to render the + # country dropdown. Operators can override to 'hidden' or 'required' via + # site configuration or YAML env config. See issue #38195. + 'country': 'optional', } ######################### Course Enrollment Modes ##########################