Repository: zulip/zulip

Issue:
Can't reuse group name after it's renamed (until refresh)
1. Make a group named **foo**
2. Rename it to **bar**
3. Try to make a new group named **foo**, or rename another existing group to **foo**.

Expected: It should work.
Actual:

<img width="633" alt="Screenshot 2023-12-08 at 9 20 52 PM" src="https://github.com/zulip/zulip/assets/2090066/c708f5a8-c9bb-4b6a-bbfb-3af252f596c9">

Refreshing the browser fixes this.


Discussion:

Resolving patch:
diff --git a/zerver/views/realm.py b/zerver/views/realm.py
--- a/zerver/views/realm.py
+++ b/zerver/views/realm.py
@@ -1,6 +1,5 @@
 from typing import Any, Dict, Mapping, Optional, Union
 
-from django.conf import settings
 from django.core.exceptions import ValidationError
 from django.http import HttpRequest, HttpResponse
 from django.shortcuts import render
@@ -236,9 +235,6 @@ def update_realm(
         realm.ensure_not_on_limited_plan()
 
     if can_access_all_users_group_id is not None:
-        # Remove this when the feature is ready for production.
-        assert settings.DEVELOPMENT
-
         realm.can_enable_restricted_user_access_for_guests()
 
     data: Dict[str, Any] = {}


Test patch:
diff --git a/web/tests/user_groups.test.js b/web/tests/user_groups.test.js
--- a/web/tests/user_groups.test.js
+++ b/web/tests/user_groups.test.js
@@ -79,7 +79,7 @@ run_test("user_groups", () => {
     });
 
     assert.equal(user_groups.get_user_group_from_name(all.name), undefined);
-    assert.equal(user_groups.get_user_group_from_name(admins.name).id, 1);
+    assert.equal(user_groups.get_user_group_from_name("new admins").id, 1);
 
     user_groups.add(all);
     const user_groups_array = user_groups.get_realm_user_groups();
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -1386,30 +1386,6 @@ def test_update_realm_properties(self) -> None:
             with self.subTest(property=prop):
                 self.do_test_realm_permission_group_setting_update_api(prop)
 
-    def test_update_can_access_all_users_group_setting(self) -> None:
-        realm = get_realm("zulip")
-        self.login("iago")
-        members_group = UserGroup.objects.get(realm=realm, name=SystemGroups.MEMBERS)
-
-        with self.settings(DEVELOPMENT=False):
-            with self.assertRaises(AssertionError), self.assertLogs(
-                "django.request", "ERROR"
-            ) as error_log:
-                self.client_patch("/json/realm", {"can_access_all_users_group": members_group.id})
-
-        self.assertTrue(
-            "ERROR:django.request:Internal Server Error: /json/realm" in error_log.output[0]
-        )
-        self.assertTrue("AssertionError" in error_log.output[0])
-
-        with self.settings(DEVELOPMENT=True):
-            result = self.client_patch(
-                "/json/realm", {"can_access_all_users_group": members_group.id}
-            )
-            self.assert_json_success(result)
-            realm = get_realm("zulip")
-            self.assertEqual(realm.can_access_all_users_group_id, members_group.id)
-
     # Not in Realm.property_types because org_type has
     # a unique RealmAuditLog event_type.
     def test_update_realm_org_type(self) -> None: