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: Fix check_full_name using admin profile during creation.

Tim Abbottfe47eef6018a
diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.py
index 0d7bf36f034..2230d3cb977 100644
--- a/zerver/tests/test_bots.py
+++ b/zerver/tests/test_bots.py
@@ -234,6 +234,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
self.get_bot_user(email)
def test_add_bot_with_username_in_use(self) -> None:
+ hamlet = self.example_user("hamlet")
self.login("hamlet")
self.assert_num_bots_equal(0)
self.create_bot()
@@ -257,6 +258,17 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
result = self.client_post("/json/bots", bot_info)
self.assert_json_error(result, "Name is already in use.")
+ # Duplicate names are not allowed for bots even when require_unique_names
+ # is false, but this test is added just for completion.
+ dup_full_name = hamlet.full_name
+ do_set_realm_property(hamlet.realm, "require_unique_names", True, acting_user=None)
+ bot_info = dict(
+ full_name=dup_full_name,
+ short_name="whatever",
+ )
+ result = self.client_post("/json/bots", bot_info)
+ self.assert_json_error(result, "Unique names required in this organization.")
+
def test_add_bot_with_user_avatar(self) -> None:
realm = get_realm("zulip")
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index bb8a64bff4c..959871e59e1 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -1499,6 +1499,24 @@ class AdminCreateUserTest(ZulipTestCase):
result = self.client_post("/json/users", valid_params)
self.assert_json_success(result)
+ # Test require_unique_names.
+ do_set_realm_property(realm, "require_unique_names", True, acting_user=None)
+ params = dict(
+ password="xxxx",
+ full_name=admin.full_name,
+ )
+ result = self.client_post("/json/users", params)
+ self.assert_json_error(result, "Unique names required in this organization.")
+
+ params["full_name"] = self.example_user("iago").full_name
+ result = self.client_post("/json/users", params)
+ self.assert_json_error(result, "Unique names required in this organization.")
+
+ params["full_name"] = "Iago new"
+ result = self.client_post("/json/users", params)
+ self.assert_json_success(result)
+
class UserProfileTest(ZulipTestCase):
def test_valid_user_id(self) -> None:
diff --git a/zerver/views/users.py b/zerver/views/users.py
index a598ec4cce4..b6b39364557 100644
--- a/zerver/views/users.py
+++ b/zerver/views/users.py
@@ -662,7 +662,7 @@ def add_bot_backend(
if bot_type != UserProfile.INCOMING_WEBHOOK_BOT:
service_name = service_name or short_name
full_name = check_full_name(
- full_name_raw=full_name_raw, user_profile=user_profile, realm=user_profile.realm
+ full_name_raw=full_name_raw, user_profile=None, realm=user_profile.realm
)
form = CreateUserForm({"full_name": full_name, "email": email})
@@ -899,7 +899,7 @@ def create_user_backend(
raise JsonableError(_("User not authorized to create users"))
full_name = check_full_name(
- full_name_raw=full_name_raw, user_profile=user_profile, realm=user_profile.realm
+ full_name_raw=full_name_raw, user_profile=None, realm=user_profile.realm
)
form = CreateUserForm({"full_name": full_name, "email": email})
if not form.is_valid():