mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
models: Enforce stricter requirements on the full_name field.
This changes the requirements for UserProfile to disallow some additional characters, with the overall goal of being able to use formataddr in send_mail.py. We don't need to be particularly careful in the database migration, because user full_names are not required to be unique.
This commit is contained in:
committed by
Tim Abbott
parent
f54a63e2f9
commit
c25dcf048d
@@ -1,5 +1,7 @@
|
||||
from typing import Dict, List, Optional, Union, cast
|
||||
|
||||
import unicodedata
|
||||
|
||||
from django.db.models.query import QuerySet
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
@@ -19,8 +21,10 @@ def check_full_name(full_name_raw: str) -> str:
|
||||
raise JsonableError(_("Name too long!"))
|
||||
if len(full_name) < UserProfile.MIN_NAME_LENGTH:
|
||||
raise JsonableError(_("Name too short!"))
|
||||
if list(set(full_name).intersection(UserProfile.NAME_INVALID_CHARS)):
|
||||
raise JsonableError(_("Invalid characters in name!"))
|
||||
for character in full_name:
|
||||
if (unicodedata.category(character)[0] == 'C' or
|
||||
character in UserProfile.NAME_INVALID_CHARS):
|
||||
raise JsonableError(_("Invalid characters in name!"))
|
||||
return full_name
|
||||
|
||||
# NOTE: We don't try to absolutely prevent 2 bots from having the same
|
||||
|
||||
Reference in New Issue
Block a user