corporate: Clean up vestiges of migrating plans to multiple realms.

In commit ea863bab5b, handle_customer_migration_from_server_to_realm
was updated to only move a remote server's plan in the case that there
is only one remote realm on the server.
This commit is contained in:
Lauryn Menard 2024-12-31 14:29:49 +01:00 committed by Tim Abbott
parent d6db6e3806
commit c01787f41a
2 changed files with 14 additions and 19 deletions

View File

@ -163,7 +163,7 @@ def remote_realm_billing_finalize_login(
This is the endpoint accessed via the billing_access_url, generated by
remote_realm_billing_entry entry.
"""
from corporate.lib.stripe import RemoteRealmBillingSession
from corporate.lib.stripe import BILLING_SUPPORT_EMAIL, RemoteRealmBillingSession
if request.method not in ["GET", "POST"]:
return HttpResponseNotAllowed(["GET", "POST"])
@ -206,15 +206,15 @@ def remote_realm_billing_finalize_login(
raise
except Exception: # nocoverage
billing_logger.exception(
"%s: Failed to migrate customer from server (id: %s) to realms",
"%s: Failed to migrate customer from server (id: %s) to realm",
request.path,
remote_server.id,
stack_info=True,
)
raise JsonableError(
_(
"Failed to migrate customer from server to realms. Please contact support for assistance."
)
"Couldn't reconcile billing data between server and realm. Please contact {support_email}"
).format(support_email=BILLING_SUPPORT_EMAIL)
)
# Redirect to error page if server is on an active plan

View File

@ -1068,7 +1068,6 @@ def handle_customer_migration_from_server_to_realm(
return
event_time = timezone_now()
remote_realm_audit_logs = []
if len(realm_uuids) != 1:
return
@ -1138,22 +1137,18 @@ def handle_customer_migration_from_server_to_realm(
remote_realm.save(update_fields=["plan_type"])
server.plan_type = RemoteZulipServer.PLAN_TYPE_SELF_MANAGED
server.save(update_fields=["plan_type"])
remote_realm_audit_logs.append(
RemoteRealmAuditLog(
server=server,
remote_realm=remote_realm,
event_type=AuditLogEventType.REMOTE_PLAN_TRANSFERRED_SERVER_TO_REALM,
event_time=event_time,
extra_data={
"attr_name": "plan_type",
"old_value": RemoteRealm.PLAN_TYPE_SELF_MANAGED,
"new_value": remote_realm.plan_type,
},
)
RemoteRealmAuditLog.objects.create(
server=server,
remote_realm=remote_realm,
event_type=AuditLogEventType.REMOTE_PLAN_TRANSFERRED_SERVER_TO_REALM,
event_time=event_time,
extra_data={
"attr_name": "plan_type",
"old_value": RemoteRealm.PLAN_TYPE_SELF_MANAGED,
"new_value": remote_realm.plan_type,
},
)
RemoteRealmAuditLog.objects.bulk_create(remote_realm_audit_logs)
@typed_endpoint
@transaction.atomic(durable=True)