Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

delete_realm: Disallow deletion of realms we've had billing plans with.

Alex Vandiver4525543ec667
diff --git a/zerver/management/commands/delete_realm.py b/zerver/management/commands/delete_realm.py
index 4efee4f4379..28424b970dd 100644
--- a/zerver/management/commands/delete_realm.py
+++ b/zerver/management/commands/delete_realm.py
@@ -1,6 +1,7 @@
from argparse import ArgumentParser
from typing import Any
+from django.conf import settings
from django.core.management.base import CommandError
from zerver.lib.management import ZulipBaseCommand
@@ -28,6 +29,15 @@ realms used for testing; consider using deactivate_realm instead."""
print(f"This realm has {user_count} users and {message_count} messages.\n")
+ if settings.BILLING_ENABLED:
+ # Deleting a Realm object also deletes associating billing
+ # metadata in an invariant-violating way, so we should
+ # never use this tool for a realm with billing setup.
+ from corporate.models import get_customer_by_realm
+
+ if get_customer_by_realm(realm):
+ raise CommandError("This realm has had a billing relationship associated with it!")
+
print(
"This command will \033[91mPERMANENTLY DELETE\033[0m all data for this realm. "
"Most use cases will be better served by scrub_realm and/or deactivate_realm."