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.

models: Make get_admin_users_and_bots optionally not return owners.

Vishnu KS7a351edb604f
diff --git a/zerver/models.py b/zerver/models.py
index b472caf2088..1b50d6d377f 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -553,16 +553,23 @@ class Realm(models.Model):
def get_active_emoji(self) -> Dict[str, Dict[str, Iterable[str]]]:
return get_active_realm_emoji_uncached(self)
- def get_admin_users_and_bots(self) -> Sequence["UserProfile"]:
+ def get_admin_users_and_bots(
+ self, include_realm_owners: bool = True
+ ) -> Sequence["UserProfile"]:
"""Use this in contexts where we want administrative users as well as
bots with administrator privileges, like send_event calls for
notifications to all administrator users.
"""
+ if include_realm_owners:
+ roles = [UserProfile.ROLE_REALM_ADMINISTRATOR, UserProfile.ROLE_REALM_OWNER]
+ else:
+ roles = [UserProfile.ROLE_REALM_ADMINISTRATOR]
+
# TODO: Change return type to QuerySet[UserProfile]
return UserProfile.objects.filter(
realm=self,
is_active=True,
- role__in=[UserProfile.ROLE_REALM_ADMINISTRATOR, UserProfile.ROLE_REALM_OWNER],
+ role__in=roles,
)
def get_human_admin_users(self) -> QuerySet:
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index e60ba27c830..19c1a2abefc 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -128,6 +128,8 @@ class PermissionTest(ZulipTestCase):
self.assertTrue(user_profile in admin_users)
admin_users = user_profile.realm.get_admin_users_and_bots()
self.assertTrue(user_profile in admin_users)
+ admin_users = user_profile.realm.get_admin_users_and_bots(include_realm_owners=False)
+ self.assertFalse(user_profile in admin_users)
def test_updating_non_existent_user(self) -> None:
self.login("hamlet")