settings: Add permission to enforce unique names in realm.

Previously, users were allowed to signup or change their names to
those which already existed in the realm.

This commit adds an Organization Permission, that shall enforce
users to use unique names while signing up or changing their
names. If a same or normalized full name is found in realm,
then a validation error is thrown.

Fixes #7830.
This commit is contained in:
roanster007
2024-03-12 00:32:05 +05:30
committed by Tim Abbott
parent a283a19c9f
commit c7a08f3b77
20 changed files with 188 additions and 13 deletions

View File

@@ -2421,6 +2421,25 @@ class UserSignUpTest(ZulipTestCase):
# Verify that the user is asked for name and password
self.assert_in_success_response(["id_password", "id_full_name"], result)
def test_signup_with_existing_name(self) -> None:
"""
Check if signing up with an existing name when organization
has set "Require Unique Names"is handled properly.
"""
iago = self.example_user("iago")
email = "newguy@zulip.com"
password = "newpassword"
do_set_realm_property(iago.realm, "require_unique_names", True, acting_user=None)
result = self.verify_signup(email=email, password=password, full_name="IaGo")
assert not isinstance(result, UserProfile)
self.assert_in_success_response(["Unique names required in this organization."], result)
do_set_realm_property(iago.realm, "require_unique_names", False, acting_user=None)
result = self.verify_signup(email=email, password=password, full_name="IaGo")
assert isinstance(result, UserProfile)
def test_signup_without_password(self) -> None:
"""
Check if signing up without a password works properly when