support: Approve sponsorship for remote server customer.

Adds ability to approve a sponsorship request for a customer
attached to a remote server via the remote server support view.
This commit is contained in:
Lauryn Menard
2023-12-02 18:21:04 +01:00
committed by Tim Abbott
parent 2218e667a6
commit 69f6d3dcb1
3 changed files with 43 additions and 5 deletions

View File

@@ -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,

View File

@@ -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:

View File

@@ -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 }}