diff --git a/openedx/core/djangoapps/user_api/accounts/api.py b/openedx/core/djangoapps/user_api/accounts/api.py index bc4fd1d1a769..f1b20fd6ab85 100644 --- a/openedx/core/djangoapps/user_api/accounts/api.py +++ b/openedx/core/djangoapps/user_api/accounts/api.py @@ -420,6 +420,10 @@ def contains_url(value): return bool(regex) if name: + # Validation for the name length + if len(name) > 255: + return _("Full name can't be longer than 255 symbols") + return _('Enter a valid name') if (contains_html(name) or contains_url(name)) else '' else: return accounts.REQUIRED_FIELD_NAME_MSG diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py index 569ec984662b..81a3158eb5bb 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py @@ -34,7 +34,8 @@ from openedx.core.djangoapps.user_api.accounts import PRIVATE_VISIBILITY from openedx.core.djangoapps.user_api.accounts.api import ( get_account_settings, - update_account_settings + update_account_settings, + get_name_validation_error ) from openedx.core.djangoapps.user_api.accounts.tests.retirement_helpers import ( # pylint: disable=unused-import RetirementTestCase, @@ -570,6 +571,13 @@ def test_change_country_removes_state(self): assert account_settings['country'] is None assert account_settings['state'] is None + def test_get_name_validation_error_too_long(self): + """ + Test validation error when the name is too long. + """ + result = get_name_validation_error("A" * 256) + assert result == "Full name can't be longer than 255 symbols" + @patch('openedx.core.djangoapps.user_api.accounts.image_helpers._PROFILE_IMAGE_SIZES', [50, 10]) @patch.dict(