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_human_admin_users optionally not return realm owners.

Vishnu KS5e0030927b84
diff --git a/zerver/models.py b/zerver/models.py
index 1b50d6d377f..3dc99d14e7c 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -572,17 +572,22 @@ class Realm(models.Model):
role__in=roles,
)
- def get_human_admin_users(self) -> QuerySet:
+ def get_human_admin_users(self, include_realm_owners: bool = True) -> QuerySet:
"""Use this in contexts where we want only human users with
administrative privileges, like sending an email to all of a
realm's administrators (bots don't have real email addresses).
"""
+ 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_bot=False,
is_active=True,
- role__in=[UserProfile.ROLE_REALM_ADMINISTRATOR, UserProfile.ROLE_REALM_OWNER],
+ role__in=roles,
)
def get_human_billing_admin_users(self) -> Sequence["UserProfile"]:
diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py
index 19c1a2abefc..d4019762a39 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -126,6 +126,8 @@ class PermissionTest(ZulipTestCase):
self.assertTrue(user_profile.is_realm_owner)
admin_users = user_profile.realm.get_human_admin_users()
self.assertTrue(user_profile in admin_users)
+ admin_users = user_profile.realm.get_human_admin_users(include_realm_owners=False)
+ self.assertFalse(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)