mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-20 14:29:25 -04:00
make user mobile num nullable if user has email_auth enabled
This commit is contained in:
@@ -105,6 +105,26 @@ class UserSchema(BaseSchema):
|
||||
"_password", "verify_codes")
|
||||
strict = True
|
||||
|
||||
@validates('name')
|
||||
def validate_name(self, value):
|
||||
if not value:
|
||||
raise ValidationError('Invalid name')
|
||||
|
||||
@validates('email_address')
|
||||
def validate_email_address(self, value):
|
||||
try:
|
||||
validate_email_address(value)
|
||||
except InvalidEmailError as e:
|
||||
raise ValidationError(str(e))
|
||||
|
||||
@validates('mobile_number')
|
||||
def validate_mobile_number(self, value):
|
||||
try:
|
||||
if value is not None:
|
||||
validate_phone_number(value, international=True)
|
||||
except InvalidPhoneError as error:
|
||||
raise ValidationError('Invalid phone number: {}'.format(error))
|
||||
|
||||
|
||||
class UserUpdateAttributeSchema(BaseSchema):
|
||||
auth_type = field_for(models.User, 'auth_type')
|
||||
@@ -132,7 +152,8 @@ class UserUpdateAttributeSchema(BaseSchema):
|
||||
@validates('mobile_number')
|
||||
def validate_mobile_number(self, value):
|
||||
try:
|
||||
validate_phone_number(value, international=True)
|
||||
if value is not None:
|
||||
validate_phone_number(value, international=True)
|
||||
except InvalidPhoneError as error:
|
||||
raise ValidationError('Invalid phone number: {}'.format(error))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user