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
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2018-11-29 20:39:53 +01:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2020-06-11 00:54:34 +02: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
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
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
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
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()
|
2020-09-02 06:20:26 +02:00
|
|
|
owner_user_ids = set(realm.get_human_owner_users().values_list("id", flat=True))
|
2020-06-10 22:05:33 +02:00
|
|
|
|
|
|
|
if admin_users:
|
2021-02-12 08:20:45 +01:00
|
|
|
print("Administrators:\n")
|
2020-06-10 22:05:33 +02:00
|
|
|
for user in admin_users:
|
|
|
|
owner_detail = ""
|
|
|
|
if user.id in owner_user_ids:
|
|
|
|
owner_detail = " [owner]"
|
2021-02-12 08:20:45 +01:00
|
|
|
print(f" {user.delivery_email} ({user.full_name}){owner_detail}")
|
2020-06-10 22:05:33 +02:00
|
|
|
|
2013-11-02 16:10:53 +01:00
|
|
|
else:
|
2021-02-12 08:20:45 +01:00
|
|
|
raise CommandError("There are no admins for this realm!")
|
2013-11-02 16:10:53 +01:00
|
|
|
|
2020-10-22 20:30:35 +02:00
|
|
|
print('\nYou can use the "change_user_role" management command to adjust roles.')
|