mirror of https://github.com/zulip/zulip.git
models: Make get_admin_users_and_bots optionally not return owners.
This commit is contained in:
parent
1a126f8bf2
commit
7a351edb60
|
@ -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:
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue