2013-11-02 16:10:53 +01:00
|
|
|
|
2016-06-04 16:52:18 +02:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
2013-11-02 16:10:53 +01:00
|
|
|
from django.core.management.base import BaseCommand
|
2017-01-04 05:30:48 +01:00
|
|
|
from zerver.models import get_realm, Realm
|
2013-11-02 16:10:53 +01:00
|
|
|
import sys
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
2015-08-21 02:10:41 +02:00
|
|
|
help = """Show the admins in a realm."""
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2015-08-21 02:10:41 +02:00
|
|
|
def add_arguments(self, parser):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (ArgumentParser) -> None
|
2015-08-21 02:10:41 +02:00
|
|
|
parser.add_argument('realm', metavar='<realm>', type=str,
|
|
|
|
help="realm to show admins for")
|
2013-11-02 16:10:53 +01:00
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
2016-06-04 16:52:18 +02:00
|
|
|
# type: (*Any, **str) -> None
|
|
|
|
realm_name = options['realm']
|
2013-11-02 16:10:53 +01:00
|
|
|
|
|
|
|
try:
|
2017-01-04 05:30:48 +01:00
|
|
|
realm = get_realm(realm_name)
|
2013-11-02 16:10:53 +01:00
|
|
|
except Realm.DoesNotExist:
|
2016-06-04 16:52:18 +02:00
|
|
|
print('There is no realm called %s.' % (realm_name,))
|
2013-11-02 16:10:53 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
users = realm.get_admin_users()
|
|
|
|
|
|
|
|
if users:
|
2015-11-01 17:11:06 +01:00
|
|
|
print('Admins:\n')
|
2013-11-02 16:10:53 +01:00
|
|
|
for user in users:
|
2015-11-01 17:11:06 +01:00
|
|
|
print(' %s (%s)' % (user.email, user.full_name))
|
2013-11-02 16:10:53 +01:00
|
|
|
else:
|
2015-11-01 17:11:06 +01:00
|
|
|
print('There are no admins for this realm!')
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2015-11-01 17:11:06 +01:00
|
|
|
print('\nYou can use the "knight" management command to knight admins.')
|