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.

support: Add downgrade current plan actions to remote servers.

Lauryn Menard6c5b41926708
diff --git a/analytics/views/support.py b/analytics/views/support.py
index 8bb5bd8b57a..30057189518 100644
--- a/analytics/views/support.py
+++ b/analytics/views/support.py
@@ -392,6 +392,9 @@ def remote_servers_support(
billing_modality: Optional[str] = REQ(
default=None, str_validator=check_string_in(VALID_BILLING_MODALITY_VALUES)
),
+ modify_plan: Optional[str] = REQ(
+ default=None, str_validator=check_string_in(VALID_MODIFY_PLAN_METHODS)
+ ),
) -> HttpResponse:
context: Dict[str, Any] = {}
@@ -432,6 +435,11 @@ def remote_servers_support(
support_type=SupportType.update_billing_modality,
billing_modality=billing_modality,
)
+ elif modify_plan is not None:
+ support_view_request = SupportViewRequest(
+ support_type=SupportType.modify_plan,
+ plan_modification=modify_plan,
+ )
if support_view_request is not None:
billing_session = RemoteServerBillingSession(
support_staff=acting_user, remote_server=remote_server
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index a6b34d696ea..a6bd9b416f0 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -551,6 +551,7 @@ class AuditLogEventType(Enum):
BILLING_MODALITY_CHANGED = 7
CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN = 8
CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN = 9
+ BILLING_ENTITY_PLAN_TYPE_CHANGED = 10
class PlanTierChangeType(Enum):
@@ -2657,6 +2658,8 @@ class RemoteRealmBillingSession(BillingSession): # nocoverage
return RemoteRealmAuditLog.REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED
elif event_type is AuditLogEventType.BILLING_MODALITY_CHANGED:
return RemoteRealmAuditLog.REMOTE_SERVER_BILLING_MODALITY_CHANGED
+ elif event_type is AuditLogEventType.BILLING_ENTITY_PLAN_TYPE_CHANGED:
+ return RemoteRealmAuditLog.REMOTE_SERVER_PLAN_TYPE_CHANGED
else:
raise BillingSessionAuditLogEventError(event_type)
@@ -2789,10 +2792,17 @@ class RemoteRealmBillingSession(BillingSession): # nocoverage
@override
def process_downgrade(self, plan: CustomerPlan) -> None:
- self.remote_realm.plan_type = RemoteRealm.PLAN_TYPE_SELF_HOSTED
- self.remote_realm.save(update_fields=["plan_type"])
+ with transaction.atomic():
+ old_plan_type = self.remote_realm.plan_type
+ new_plan_type = RemoteRealm.PLAN_TYPE_SELF_HOSTED
+ self.remote_realm.plan_type = new_plan_type
+ self.remote_realm.save(update_fields=["plan_type"])
+ self.write_to_audit_log(
+ event_type=AuditLogEventType.BILLING_ENTITY_PLAN_TYPE_CHANGED,
+ event_time=timezone_now(),
+ extra_data={"old_value": old_plan_type, "new_value": new_plan_type},
+ )
- # TODO: Write audit log entry
plan.status = CustomerPlan.ENDED
plan.save(update_fields=["status"])
@@ -2937,6 +2947,8 @@ class RemoteServerBillingSession(BillingSession): # nocoverage
return RemoteZulipServerAuditLog.REMOTE_SERVER_SPONSORSHIP_PENDING_STATUS_CHANGED
elif event_type is AuditLogEventType.BILLING_MODALITY_CHANGED:
return RemoteZulipServerAuditLog.REMOTE_SERVER_BILLING_MODALITY_CHANGED
+ elif event_type is AuditLogEventType.BILLING_ENTITY_PLAN_TYPE_CHANGED:
+ return RemoteZulipServerAuditLog.REMOTE_SERVER_PLAN_TYPE_CHANGED
else:
raise BillingSessionAuditLogEventError(event_type)
@@ -3044,10 +3056,17 @@ class RemoteServerBillingSession(BillingSession): # nocoverage
@override
def process_downgrade(self, plan: CustomerPlan) -> None:
- self.remote_server.plan_type = RemoteZulipServer.PLAN_TYPE_SELF_HOSTED
- self.remote_server.save(update_fields=["plan_type"])
+ with transaction.atomic():
+ old_plan_type = self.remote_server.plan_type
+ new_plan_type = RemoteZulipServer.PLAN_TYPE_SELF_HOSTED
+ self.remote_server.plan_type = new_plan_type
+ self.remote_server.save(update_fields=["plan_type"])
+ self.write_to_audit_log(
+ event_type=AuditLogEventType.BILLING_ENTITY_PLAN_TYPE_CHANGED,
+ event_time=timezone_now(),
+ extra_data={"old_value": old_plan_type, "new_value": new_plan_type},
+ )
- # TODO: Write audit log entry
plan.status = CustomerPlan.ENDED
plan.save(update_fields=["status"])
diff --git a/templates/analytics/remote_server_support.html b/templates/analytics/remote_server_support.html
index 34160275beb..0feee3df8cd 100644
--- a/templates/analytics/remote_server_support.html
+++ b/templates/analytics/remote_server_support.html
@@ -118,6 +118,19 @@
</select>
<button type="submit" class="btn btn-default support-submit-button">Update</button>
</form>
+
+ <form method="POST" class="remote-server-form">
+ <b>Modify current plan</b><br />
+ {{ csrf_input }}
+ <input type="hidden" name="remote_server_id" value="{{ remote_server.id }}" />
+ <select name="modify_plan" class="modify-plan-method-select" required>
+ <option disabled value="" selected>-- select --</option>
+ <option value="downgrade_at_billing_cycle_end">Downgrade at the end of current billing cycle</option>
+ <option value="downgrade_now_without_additional_licenses">Downgrade now without creating additional invoices</option>
+ <option value="downgrade_now_void_open_invoices">Downgrade now and void open invoices</option>
+ </select>
+ <button type="submit" class="btn btn-default support-submit-button">Modify</button>
+ </form>
{% endif %}
</div>
{% endfor %}