snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
80
zerver/management/commands/list_realms.py
Normal file
80
zerver/management/commands/list_realms.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import sys
|
||||
from argparse import ArgumentParser
|
||||
from typing import Any
|
||||
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
from zerver.models import Realm
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
help = """List realms in the server and it's configuration settings(optional).
|
||||
|
||||
Usage examples:
|
||||
|
||||
./manage.py list_realms
|
||||
./manage.py list_realms --all"""
|
||||
|
||||
@override
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
parser.add_argument(
|
||||
"--all", action="store_true", help="Print all the configuration settings of the realms."
|
||||
)
|
||||
|
||||
@override
|
||||
def handle(self, *args: Any, **options: Any) -> None:
|
||||
realms = Realm.objects.all()
|
||||
|
||||
outer_format = "{:<5} {:<20} {!s:<30} {:<50}"
|
||||
inner_format = "{:<40} {}"
|
||||
deactivated = False
|
||||
|
||||
if not options["all"]:
|
||||
print(outer_format.format("id", "string_id", "name", "domain"))
|
||||
print(outer_format.format("--", "---------", "----", "------"))
|
||||
|
||||
for realm in realms:
|
||||
display_string_id = realm.string_id if realm.string_id != "" else "''"
|
||||
if realm.deactivated:
|
||||
print(
|
||||
self.style.ERROR(
|
||||
outer_format.format(realm.id, display_string_id, realm.name, realm.url)
|
||||
)
|
||||
)
|
||||
deactivated = True
|
||||
else:
|
||||
print(outer_format.format(realm.id, display_string_id, realm.name, realm.url))
|
||||
if deactivated:
|
||||
print(self.style.WARNING("\nRed rows represent deactivated realms."))
|
||||
sys.exit(0)
|
||||
|
||||
# The remaining code path is the --all case.
|
||||
identifier_attributes = ["id", "name", "string_id"]
|
||||
for realm in realms:
|
||||
# Start with just all the fields on the object, which is
|
||||
# hacky but doesn't require any work to maintain.
|
||||
realm_dict = vars(realm).copy()
|
||||
# Remove a field that is confusingly useless
|
||||
del realm_dict["_state"]
|
||||
|
||||
# This is not an attribute of realm strictly speaking, but valuable info to include.
|
||||
realm_dict["authentication_methods"] = str(realm.authentication_methods_dict())
|
||||
|
||||
for key in identifier_attributes:
|
||||
if realm.deactivated:
|
||||
print(self.style.ERROR(inner_format.format(key, realm_dict[key])))
|
||||
deactivated = True
|
||||
else:
|
||||
print(inner_format.format(key, realm_dict[key]))
|
||||
|
||||
for key, value in sorted(realm_dict.items()):
|
||||
if key not in identifier_attributes:
|
||||
if realm.deactivated:
|
||||
print(self.style.ERROR(inner_format.format(key, value)))
|
||||
else:
|
||||
print(inner_format.format(key, value))
|
||||
print("-" * 80)
|
||||
|
||||
if deactivated:
|
||||
print(self.style.WARNING("\nRed is used to highlight deactivated realms."))
|
||||
Reference in New Issue
Block a user