Merge pull request #30488 from openedx/sajjad/VAN-965
fix: Name field validation issue [VAN-965] The name validation error was being removed after backend validation VAN-965
This commit is contained in:
@@ -5,6 +5,7 @@ Programmatic integration point for User API Accounts sub-application
|
||||
|
||||
|
||||
import datetime
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
@@ -403,7 +404,11 @@ def get_name_validation_error(name):
|
||||
:return: Validation error message.
|
||||
|
||||
"""
|
||||
return '' if name else accounts.REQUIRED_FIELD_NAME_MSG
|
||||
if name:
|
||||
regex = re.findall(r'https|http?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', name)
|
||||
return _('Enter a valid name') if bool(regex) else ''
|
||||
else:
|
||||
return accounts.REQUIRED_FIELD_NAME_MSG
|
||||
|
||||
|
||||
def get_username_validation_error(username):
|
||||
|
||||
@@ -792,8 +792,11 @@ class RegistrationValidationView(APIView):
|
||||
def name_handler(self, request):
|
||||
""" Validates whether fullname is valid """
|
||||
name = request.data.get('name')
|
||||
validation_error = get_name_validation_error(name)
|
||||
if validation_error:
|
||||
return validation_error
|
||||
self.username_suggestions = generate_username_suggestions(name)
|
||||
return get_name_validation_error(name)
|
||||
return validation_error
|
||||
|
||||
def username_handler(self, request):
|
||||
""" Validates whether the username is valid. """
|
||||
|
||||
Reference in New Issue
Block a user