2017-11-16 00:43:27 +01:00
|
|
|
from argparse import ArgumentParser
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
2020-06-10 22:05:33 +02:00
|
|
|
from django.core.management.base import CommandError
|
2018-11-29 20:39:53 +01:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2018-11-29 20:39:53 +01:00
|
|
|
class Command(ZulipBaseCommand):
|
2020-06-10 22:05:33 +02:00
|
|
|
help = """Show the owners and administrators in an organization."""
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2017-10-26 11:35:57 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2018-11-29 20:39:53 +01:00
|
|
|
self.add_realm_args(parser, required=True)
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2018-11-29 20:39:53 +01:00
|
|
|
def handle(self, *args: Any, **options: Any) -> None:
|
|
|
|
realm = self.get_realm(options)
|
2018-11-29 20:51:39 +01:00
|
|
|
assert realm is not None # True because of required=True above
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2020-06-10 22:05:33 +02:00
|
|
|
admin_users = realm.get_admin_users_and_bots()
|
|
|
|
owner_user_ids = set(list(realm.get_human_owner_users().values_list("id", flat=True)))
|
|
|
|
|
|
|
|
if admin_users:
|
|
|
|
print('Administrators:\n')
|
|
|
|
for user in admin_users:
|
|
|
|
owner_detail = ""
|
|
|
|
if user.id in owner_user_ids:
|
|
|
|
owner_detail = " [owner]"
|
|
|
|
print(' %s (%s)%s' % (user.delivery_email, user.full_name, owner_detail))
|
|
|
|
|
2013-11-02 16:10:53 +01:00
|
|
|
else:
|
2020-06-10 22:05:33 +02:00
|
|
|
raise CommandError('There are no admins for this realm!')
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2018-11-29 20:39:53 +01:00
|
|
|
print('\nYou can use the "knight" management command to make more users admins.')
|
|
|
|
print('\nOr with the --revoke argument, remove admin status from users.')
|