2018-09-14 13:14:40 +02:00
|
|
|
from argparse import ArgumentParser
|
|
|
|
from typing import Any
|
|
|
|
|
2022-12-05 09:27:43 +01:00
|
|
|
from django.core.management.base import CommandError
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
2022-12-05 09:27:43 +01:00
|
|
|
|
2022-04-14 23:57:15 +02:00
|
|
|
from zerver.actions.realm_settings import do_scrub_realm
|
2018-09-14 13:14:40 +02:00
|
|
|
from zerver.lib.management import ZulipBaseCommand
|
|
|
|
|
2020-01-14 21:59:46 +01:00
|
|
|
|
2018-09-14 13:14:40 +02:00
|
|
|
class Command(ZulipBaseCommand):
|
|
|
|
help = """Script to scrub a deactivated realm."""
|
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2018-09-14 13:14:40 +02:00
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
2021-05-10 21:29:25 +02:00
|
|
|
self.add_realm_args(parser, required=True)
|
2018-09-14 13:14:40 +02:00
|
|
|
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2018-09-14 13:14:40 +02:00
|
|
|
def handle(self, *args: Any, **options: str) -> None:
|
|
|
|
realm = self.get_realm(options)
|
|
|
|
assert realm is not None # Should be ensured by parser
|
|
|
|
if not realm.deactivated:
|
2022-12-05 09:27:43 +01:00
|
|
|
raise CommandError(
|
|
|
|
f'Realm {options["realm_id"]} is active. Please deactivate the realm the first.'
|
|
|
|
)
|
2018-09-14 13:14:40 +02:00
|
|
|
print("Scrubbing", options["realm_id"])
|
2020-06-29 12:28:21 +02:00
|
|
|
do_scrub_realm(realm, acting_user=None)
|
2018-09-14 13:14:40 +02:00
|
|
|
print("Done!")
|