Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

users: Allow 1-character names.

Alex Vandiver839135d00728
diff --git a/zerver/lib/users.py b/zerver/lib/users.py
index eecdaf9afb6..cf1df12a3b4 100644
--- a/zerver/lib/users.py
+++ b/zerver/lib/users.py
@@ -58,8 +58,8 @@ def check_full_name(
full_name = full_name_raw.strip()
if len(full_name) > UserProfile.MAX_NAME_LENGTH:
raise JsonableError(_("Name too long!"))
- if len(full_name) < UserProfile.MIN_NAME_LENGTH:
- raise JsonableError(_("Name too short!"))
+ if len(full_name) == 0:
+ raise JsonableError(_("Name must not be empty!"))
if check_string_is_printable(full_name) is not None or any(
character in full_name for character in UserProfile.NAME_INVALID_CHARS
):
diff --git a/zerver/models/users.py b/zerver/models/users.py
index b635c4081f2..a4012346bb2 100644
--- a/zerver/models/users.py
+++ b/zerver/models/users.py
@@ -459,7 +459,6 @@ class RealmUserDefault(UserBaseSettings):
class UserProfile(AbstractBaseUser, PermissionsMixin, UserBaseSettings):
USERNAME_FIELD = "email"
MAX_NAME_LENGTH = 100
- MIN_NAME_LENGTH = 2
API_KEY_LENGTH = 32
NAME_INVALID_CHARS = ["*", "`", "\\", ">", '"', "@"]
diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py
index 6ad8beaf48d..6ae74d0b6e5 100644
--- a/zerver/tests/test_auth_backends.py
+++ b/zerver/tests/test_auth_backends.py
@@ -7487,8 +7487,8 @@ class TestZulipLDAPUserPopulator(ZulipLDAPTestCase):
self.perform_ldap_sync(self.example_user("hamlet"))
fn.assert_not_called()
- def test_too_short_name(self) -> None:
- self.change_ldap_user_attr("hamlet", "cn", "a")
+ def test_empty_name(self) -> None:
+ self.change_ldap_user_attr("hamlet", "cn", "")
with (
self.assertRaises(ZulipLDAPError),
@@ -7496,7 +7496,7 @@ class TestZulipLDAPUserPopulator(ZulipLDAPTestCase):
):
self.perform_ldap_sync(self.example_user("hamlet"))
self.assertIn(
- "DEBUG:django_auth_ldap:Failed to populate user hamlet: Name too short!",
+ "DEBUG:django_auth_ldap:Failed to populate user hamlet: Name must not be empty!",
debug_log.output,
)
diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.py
index cdd02ffa64d..45468b24f69 100644
--- a/zerver/tests/test_bots.py
+++ b/zerver/tests/test_bots.py
@@ -135,11 +135,11 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
self.login("hamlet")
self.assert_num_bots_equal(0)
bot_info = dict(
- full_name="a",
+ full_name="",
short_name="bot",
)
result = self.client_post("/json/bots", bot_info)
- self.assert_json_error(result, "Name too short!")
+ self.assert_json_error(result, "Name must not be empty!")
self.assert_num_bots_equal(0)
def test_json_users_with_bots(self) -> None:
diff --git a/zerver/tests/test_settings.py b/zerver/tests/test_settings.py
index d4f86219b8f..f74c7c9d4e7 100644
--- a/zerver/tests/test_settings.py
+++ b/zerver/tests/test_settings.py
@@ -116,10 +116,8 @@ class ChangeSettingsTest(ZulipTestCase):
self.assert_json_error(json_result, "Name too long!")
# Now try too-short names
- short_names = ["", "x"]
- for name in short_names:
- json_result = self.client_patch("/json/settings", dict(full_name=name))
- self.assert_json_error(json_result, "Name too short!")
+ json_result = self.client_patch("/json/settings", dict(full_name=""))
+ self.assert_json_error(json_result, "Name must not be empty!")
def test_illegal_characters_in_name_changes(self) -> None:
self.login("hamlet")
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index 91e87b24aaa..17f54814620 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -431,12 +431,14 @@ class PermissionTest(ZulipTestCase):
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
self.assert_json_error(result, "Name too long!")
- def test_admin_cannot_set_short_full_name(self) -> None:
- new_name = "a"
+ def test_admin_cannot_set_empty_full_name(self) -> None:
self.login("iago")
- req = dict(full_name=new_name)
+ req = dict(full_name="")
+ # Empty name is treated as a no-op
result = self.client_patch("/json/users/{}".format(self.example_user("hamlet").id), req)
- self.assert_json_error(result, "Name too short!")
+ self.assert_json_success(result)
+ iago = self.example_user("iago")
+ self.assertEqual(iago.full_name, "Iago")
def test_not_allowed_format(self) -> None:
# Name of format "Alice|999" breaks in Markdown