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: Approve sponsorship for remote server customer.

Lauryn Menard69f6d3dcb167
diff --git a/analytics/views/support.py b/analytics/views/support.py
index 744af00d14c..f77a3c52341 100644
--- a/analytics/views/support.py
+++ b/analytics/views/support.py
@@ -388,6 +388,7 @@ def remote_servers_support(
remote_server_id: Optional[int] = REQ(default=None, converter=to_non_negative_int),
discount: Optional[Decimal] = REQ(default=None, converter=to_decimal),
sponsorship_pending: Optional[bool] = REQ(default=None, json_validator=check_bool),
+ approve_sponsorship: bool = REQ(default=False, json_validator=check_bool),
) -> HttpResponse:
context: Dict[str, Any] = {}
@@ -411,7 +412,9 @@ def remote_servers_support(
support_view_request = None
- if sponsorship_pending is not None:
+ if approve_sponsorship:
+ support_view_request = SupportViewRequest(support_type=SupportType.approve_sponsorship)
+ elif sponsorship_pending is not None:
support_view_request = SupportViewRequest(
support_type=SupportType.update_sponsorship_status,
sponsorship_status=sponsorship_pending,
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py
index 13d591a2a04..dfa7836bfcb 100644
--- a/corporate/lib/stripe.py
+++ b/corporate/lib/stripe.py
@@ -2580,8 +2580,20 @@ class RemoteRealmBillingSession(BillingSession): # nocoverage
@override
def approve_sponsorship(self) -> str:
- # TBD
- return ""
+ # Sponsorship approval is only a support admin action.
+ assert self.support_session
+
+ self.do_change_plan_type(tier=None, is_sponsored=True)
+ customer = self.get_customer()
+ if customer is not None and customer.sponsorship_pending:
+ customer.sponsorship_pending = False
+ customer.save(update_fields=["sponsorship_pending"])
+ self.write_to_audit_log(
+ event_type=AuditLogEventType.SPONSORSHIP_APPROVED, event_time=timezone_now()
+ )
+ # TODO: Add something (probably email) to let remote realm
+ # organization know that the sponsorship request was approved.
+ return f"Sponsorship approved for {self.billing_entity_display_name}"
@override
def is_sponsored(self) -> bool:
@@ -2848,8 +2860,20 @@ class RemoteServerBillingSession(BillingSession): # nocoverage
@override
def approve_sponsorship(self) -> str:
- # TBD
- return ""
+ # Sponsorship approval is only a support admin action.
+ assert self.support_session
+
+ self.do_change_plan_type(tier=None, is_sponsored=True)
+ customer = self.get_customer()
+ if customer is not None and customer.sponsorship_pending:
+ customer.sponsorship_pending = False
+ customer.save(update_fields=["sponsorship_pending"])
+ self.write_to_audit_log(
+ event_type=AuditLogEventType.SPONSORSHIP_APPROVED, event_time=timezone_now()
+ )
+ # TODO: Add something (probably email) to let remote server
+ # organization know that the sponsorship request was approved.
+ return f"Sponsorship approved for {self.billing_entity_display_name}"
@override
def process_downgrade(self, plan: CustomerPlan) -> None:
diff --git a/templates/analytics/remote_server_support.html b/templates/analytics/remote_server_support.html
index 77c7139c419..5382d5d1fb1 100644
--- a/templates/analytics/remote_server_support.html
+++ b/templates/analytics/remote_server_support.html
@@ -58,6 +58,17 @@
<button type="submit" class="btn btn-default support-submit-button">Update</button>
</form>
+ {% if plan_data[remote_server.id].customer and plan_data[remote_server.id].customer.sponsorship_pending %}
+ <form method="POST" class="">
+ {{ csrf_input }}
+ <input type="hidden" name="remote_server_id" value="{{ remote_server.id }}" />
+ <input type="hidden" name="approve_sponsorship" value="true" />
+ <button class="btn btn-default sea-green small approve-sponsorship-button">
+ Approve full sponsorship
+ </button>
+ </form>
+ {% endif %}
+
<form method="POST" class="remote-server-form">
<b>Discount</b>:<br />
{{ csrf_input }}