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: Allow deletion of realms with empty customers.

Alex Vandiver6fe67f0143f0
diff --git a/zerver/management/commands/delete_realm.py b/zerver/management/commands/delete_realm.py
index 28424b970dd..d75e7ac42d4 100644
--- a/zerver/management/commands/delete_realm.py
+++ b/zerver/management/commands/delete_realm.py
@@ -33,10 +33,17 @@ realms used for testing; consider using deactivate_realm instead."""
# 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!")
+ from corporate.models import CustomerPlan, get_customer_by_realm
+
+ customer = get_customer_by_realm(realm)
+ if customer:
+ if (
+ customer.stripe_customer_id
+ or CustomerPlan.objects.filter(customer=customer).count() > 0
+ ):
+ 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. "