mirror of https://github.com/zulip/zulip.git
support: Include sponsorship request for remote server support view.
Preparation for updating the sponsorship forms template to include information about the latest sponsorship request if sponsorship is pending.
This commit is contained in:
parent
35b644c564
commit
e8500fbdb0
|
@ -60,8 +60,10 @@ if settings.BILLING_ENABLED:
|
||||||
)
|
)
|
||||||
from corporate.lib.support import (
|
from corporate.lib.support import (
|
||||||
PlanData,
|
PlanData,
|
||||||
|
SupportData,
|
||||||
get_current_plan_data_for_support_view,
|
get_current_plan_data_for_support_view,
|
||||||
get_customer_discount_for_support_view,
|
get_customer_discount_for_support_view,
|
||||||
|
get_data_for_support_view,
|
||||||
)
|
)
|
||||||
from corporate.models import CustomerPlan
|
from corporate.models import CustomerPlan
|
||||||
|
|
||||||
|
@ -476,8 +478,8 @@ def remote_servers_support(
|
||||||
email_to_search=email_to_search, hostname_to_search=hostname_to_search
|
email_to_search=email_to_search, hostname_to_search=hostname_to_search
|
||||||
)
|
)
|
||||||
remote_server_to_max_monthly_messages: Dict[int, Union[int, str]] = dict()
|
remote_server_to_max_monthly_messages: Dict[int, Union[int, str]] = dict()
|
||||||
server_plan_data: Dict[int, PlanData] = {}
|
server_support_data: Dict[int, SupportData] = {}
|
||||||
realm_plan_data: Dict[int, PlanData] = {}
|
realm_support_data: Dict[int, SupportData] = {}
|
||||||
remote_realms: Dict[int, List[RemoteRealm]] = {}
|
remote_realms: Dict[int, List[RemoteRealm]] = {}
|
||||||
for remote_server in remote_servers:
|
for remote_server in remote_servers:
|
||||||
# Get remote realms attached to remote server
|
# Get remote realms attached to remote server
|
||||||
|
@ -488,12 +490,12 @@ def remote_servers_support(
|
||||||
# Get plan data for remote realms
|
# Get plan data for remote realms
|
||||||
for remote_realm in remote_realms[remote_server.id]:
|
for remote_realm in remote_realms[remote_server.id]:
|
||||||
realm_billing_session = RemoteRealmBillingSession(remote_realm=remote_realm)
|
realm_billing_session = RemoteRealmBillingSession(remote_realm=remote_realm)
|
||||||
remote_realm_plan_data = get_current_plan_data_for_support_view(realm_billing_session)
|
remote_realm_data = get_data_for_support_view(realm_billing_session)
|
||||||
realm_plan_data[remote_realm.id] = remote_realm_plan_data
|
realm_support_data[remote_realm.id] = remote_realm_data
|
||||||
# Get plan data for remote server
|
# Get plan data for remote server
|
||||||
server_billing_session = RemoteServerBillingSession(remote_server=remote_server)
|
server_billing_session = RemoteServerBillingSession(remote_server=remote_server)
|
||||||
remote_server_plan_data = get_current_plan_data_for_support_view(server_billing_session)
|
remote_server_data = get_data_for_support_view(server_billing_session)
|
||||||
server_plan_data[remote_server.id] = remote_server_plan_data
|
server_support_data[remote_server.id] = remote_server_data
|
||||||
# Get max monthly messages
|
# Get max monthly messages
|
||||||
try:
|
try:
|
||||||
remote_server_to_max_monthly_messages[remote_server.id] = compute_max_monthly_messages(
|
remote_server_to_max_monthly_messages[remote_server.id] = compute_max_monthly_messages(
|
||||||
|
@ -503,11 +505,10 @@ def remote_servers_support(
|
||||||
remote_server_to_max_monthly_messages[remote_server.id] = "Recent data missing"
|
remote_server_to_max_monthly_messages[remote_server.id] = "Recent data missing"
|
||||||
|
|
||||||
context["remote_servers"] = remote_servers
|
context["remote_servers"] = remote_servers
|
||||||
context["remote_servers_plan_data"] = server_plan_data
|
context["remote_servers_support_data"] = server_support_data
|
||||||
context["remote_server_to_max_monthly_messages"] = remote_server_to_max_monthly_messages
|
context["remote_server_to_max_monthly_messages"] = remote_server_to_max_monthly_messages
|
||||||
context["remote_realms"] = remote_realms
|
context["remote_realms"] = remote_realms
|
||||||
context["remote_realms_plan_data"] = realm_plan_data
|
context["remote_realms_support_data"] = realm_support_data
|
||||||
context["get_discount"] = get_customer_discount_for_support_view
|
|
||||||
context["get_plan_type_name"] = get_plan_type_string
|
context["get_plan_type_name"] = get_plan_type_string
|
||||||
context["get_org_type_display_name"] = get_org_type_display_name
|
context["get_org_type_display_name"] = get_org_type_display_name
|
||||||
context["SPONSORED_PLAN_TYPE"] = RemoteZulipServer.PLAN_TYPE_COMMUNITY
|
context["SPONSORED_PLAN_TYPE"] = RemoteZulipServer.PLAN_TYPE_COMMUNITY
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import Optional
|
from typing import Optional, TypedDict
|
||||||
from urllib.parse import urlencode, urljoin, urlunsplit
|
from urllib.parse import urlencode, urljoin, urlunsplit
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -8,11 +8,33 @@ from django.urls import reverse
|
||||||
from django.utils.timezone import now as timezone_now
|
from django.utils.timezone import now as timezone_now
|
||||||
|
|
||||||
from corporate.lib.stripe import BillingSession
|
from corporate.lib.stripe import BillingSession
|
||||||
from corporate.models import Customer, CustomerPlan, get_current_plan_by_customer
|
from corporate.models import (
|
||||||
from zerver.models import Realm, get_realm
|
Customer,
|
||||||
|
CustomerPlan,
|
||||||
|
ZulipSponsorshipRequest,
|
||||||
|
get_current_plan_by_customer,
|
||||||
|
)
|
||||||
|
from zerver.models import Realm, get_org_type_display_name, get_realm
|
||||||
from zilencer.lib.remote_counts import MissingDataError
|
from zilencer.lib.remote_counts import MissingDataError
|
||||||
|
|
||||||
|
|
||||||
|
class SponsorshipRequestDict(TypedDict):
|
||||||
|
org_type: str
|
||||||
|
org_website: str
|
||||||
|
org_description: str
|
||||||
|
total_users: str
|
||||||
|
paid_users: str
|
||||||
|
paid_users_description: str
|
||||||
|
requested_plan: str
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class SponsorshipData:
|
||||||
|
sponsorship_pending: bool = False
|
||||||
|
default_discount: Optional[Decimal] = None
|
||||||
|
latest_sponsorship_request: Optional[SponsorshipRequestDict] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class PlanData:
|
class PlanData:
|
||||||
customer: Optional["Customer"] = None
|
customer: Optional["Customer"] = None
|
||||||
|
@ -24,6 +46,12 @@ class PlanData:
|
||||||
warning: Optional[str] = None
|
warning: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class SupportData:
|
||||||
|
plan_data: PlanData
|
||||||
|
sponsorship_data: SponsorshipData
|
||||||
|
|
||||||
|
|
||||||
def get_realm_support_url(realm: Realm) -> str:
|
def get_realm_support_url(realm: Realm) -> str:
|
||||||
support_realm_uri = get_realm(settings.STAFF_SUBDOMAIN).uri
|
support_realm_uri = get_realm(settings.STAFF_SUBDOMAIN).uri
|
||||||
support_url = urljoin(
|
support_url = urljoin(
|
||||||
|
@ -41,6 +69,40 @@ def get_customer_discount_for_support_view(
|
||||||
return customer.default_discount
|
return customer.default_discount
|
||||||
|
|
||||||
|
|
||||||
|
def get_customer_sponsorship_data(customer: Customer) -> SponsorshipData:
|
||||||
|
pending = customer.sponsorship_pending
|
||||||
|
discount = customer.default_discount
|
||||||
|
sponsorship_request = None
|
||||||
|
if pending:
|
||||||
|
last_sponsorship_request = (
|
||||||
|
ZulipSponsorshipRequest.objects.filter(customer=customer).order_by("id").last()
|
||||||
|
)
|
||||||
|
if last_sponsorship_request is not None:
|
||||||
|
org_type_name = get_org_type_display_name(last_sponsorship_request.org_type)
|
||||||
|
if (
|
||||||
|
last_sponsorship_request.org_website is None
|
||||||
|
or last_sponsorship_request.org_website == ""
|
||||||
|
):
|
||||||
|
website = "No website submitted"
|
||||||
|
else:
|
||||||
|
website = last_sponsorship_request.org_website
|
||||||
|
sponsorship_request = SponsorshipRequestDict(
|
||||||
|
org_type=org_type_name,
|
||||||
|
org_website=website,
|
||||||
|
org_description=last_sponsorship_request.org_description,
|
||||||
|
total_users=last_sponsorship_request.expected_total_users,
|
||||||
|
paid_users=last_sponsorship_request.paid_users_count,
|
||||||
|
paid_users_description=last_sponsorship_request.paid_users_description,
|
||||||
|
requested_plan=last_sponsorship_request.requested_plan,
|
||||||
|
)
|
||||||
|
|
||||||
|
return SponsorshipData(
|
||||||
|
sponsorship_pending=pending,
|
||||||
|
default_discount=discount,
|
||||||
|
latest_sponsorship_request=sponsorship_request,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_current_plan_data_for_support_view(billing_session: BillingSession) -> PlanData:
|
def get_current_plan_data_for_support_view(billing_session: BillingSession) -> PlanData:
|
||||||
customer = billing_session.get_customer()
|
customer = billing_session.get_customer()
|
||||||
plan = None
|
plan = None
|
||||||
|
@ -69,3 +131,17 @@ def get_current_plan_data_for_support_view(billing_session: BillingSession) -> P
|
||||||
plan_data.has_fixed_price = plan_data.current_plan.fixed_price is not None
|
plan_data.has_fixed_price = plan_data.current_plan.fixed_price is not None
|
||||||
|
|
||||||
return plan_data
|
return plan_data
|
||||||
|
|
||||||
|
|
||||||
|
def get_data_for_support_view(billing_session: BillingSession) -> SupportData:
|
||||||
|
plan_data = get_current_plan_data_for_support_view(billing_session)
|
||||||
|
customer = billing_session.get_customer()
|
||||||
|
if customer is not None:
|
||||||
|
sponsorship_data = get_customer_sponsorship_data(customer)
|
||||||
|
else:
|
||||||
|
sponsorship_data = SponsorshipData()
|
||||||
|
|
||||||
|
return SupportData(
|
||||||
|
plan_data=plan_data,
|
||||||
|
sponsorship_data=sponsorship_data,
|
||||||
|
)
|
||||||
|
|
|
@ -11,25 +11,24 @@
|
||||||
|
|
||||||
{% if remote_realm.plan_type != SPONSORED_PLAN_TYPE %}
|
{% if remote_realm.plan_type != SPONSORED_PLAN_TYPE %}
|
||||||
{% with %}
|
{% with %}
|
||||||
{% set customer = plan_data[remote_realm.id].customer %}
|
{% set sponsorship_data = support_data[remote_realm.id].sponsorship_data %}
|
||||||
{% set remote_id = remote_realm.id %}
|
{% set remote_id = remote_realm.id %}
|
||||||
{% set remote_type = "remote_realm_id" %}
|
{% set remote_type = "remote_realm_id" %}
|
||||||
{% set has_fixed_price = plan_data[remote_realm.id].has_fixed_price %}
|
{% set has_fixed_price = support_data[remote_realm.id].plan_data.has_fixed_price %}
|
||||||
{% set get_discount = get_discount %}
|
|
||||||
{% include 'analytics/sponsorship_forms_support.html' %}
|
{% include 'analytics/sponsorship_forms_support.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if plan_data[remote_realm.id].current_plan %}
|
{% if support_data[remote_realm.id].plan_data.current_plan %}
|
||||||
<div class="remote-realm-information">
|
<div class="remote-realm-information">
|
||||||
{% with %}
|
{% with %}
|
||||||
{% set plan_data = plan_data[remote_realm.id] %}
|
{% set plan_data = support_data[remote_realm.id].plan_data %}
|
||||||
{% include 'analytics/current_plan_details.html' %}
|
{% include 'analytics/current_plan_details.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% with %}
|
{% with %}
|
||||||
{% set current_plan = plan_data[remote_realm.id].current_plan %}
|
{% set current_plan = support_data[remote_realm.id].plan_data.current_plan %}
|
||||||
{% set remote_id = remote_realm.id %}
|
{% set remote_id = remote_realm.id %}
|
||||||
{% set remote_type = "remote_realm_id" %}
|
{% set remote_type = "remote_realm_id" %}
|
||||||
{% include 'analytics/current_plan_forms_support.html' %}
|
{% include 'analytics/current_plan_forms_support.html' %}
|
||||||
|
|
|
@ -54,25 +54,24 @@
|
||||||
|
|
||||||
{% if remote_server.plan_type != SPONSORED_PLAN_TYPE %}
|
{% if remote_server.plan_type != SPONSORED_PLAN_TYPE %}
|
||||||
{% with %}
|
{% with %}
|
||||||
{% set customer = remote_servers_plan_data[remote_server.id].customer %}
|
{% set sponsorship_data = remote_servers_support_data[remote_server.id].sponsorship_data %}
|
||||||
{% set remote_id = remote_server.id %}
|
{% set remote_id = remote_server.id %}
|
||||||
{% set remote_type = "remote_server_id" %}
|
{% set remote_type = "remote_server_id" %}
|
||||||
{% set has_fixed_price = remote_servers_plan_data[remote_server.id].has_fixed_price %}
|
{% set has_fixed_price = remote_servers_support_data[remote_server.id].plan_data.has_fixed_price %}
|
||||||
{% set get_discount = get_discount %}
|
|
||||||
{% include 'analytics/sponsorship_forms_support.html' %}
|
{% include 'analytics/sponsorship_forms_support.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if remote_servers_plan_data[remote_server.id].current_plan %}
|
{% if remote_servers_support_data[remote_server.id].plan_data.current_plan %}
|
||||||
<div class="remote-server-information">
|
<div class="remote-server-information">
|
||||||
{% with %}
|
{% with %}
|
||||||
{% set plan_data = remote_servers_plan_data[remote_server.id] %}
|
{% set plan_data = remote_servers_support_data[remote_server.id].plan_data %}
|
||||||
{% include 'analytics/current_plan_details.html' %}
|
{% include 'analytics/current_plan_details.html' %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% with %}
|
{% with %}
|
||||||
{% set current_plan = remote_servers_plan_data[remote_server.id].current_plan %}
|
{% set current_plan = remote_servers_support_data[remote_server.id].plan_data.current_plan %}
|
||||||
{% set remote_id = remote_server.id %}
|
{% set remote_id = remote_server.id %}
|
||||||
{% set remote_type = "remote_server_id" %}
|
{% set remote_type = "remote_server_id" %}
|
||||||
{% include 'analytics/current_plan_forms_support.html' %}
|
{% include 'analytics/current_plan_forms_support.html' %}
|
||||||
|
@ -83,7 +82,7 @@
|
||||||
<hr />
|
<hr />
|
||||||
<div>
|
<div>
|
||||||
{% with %}
|
{% with %}
|
||||||
{% set plan_data = remote_realms_plan_data %}
|
{% set support_data = remote_realms_support_data %}
|
||||||
{% set get_discount = get_discount %}
|
{% set get_discount = get_discount %}
|
||||||
{% include "analytics/remote_realm_details.html" %}
|
{% include "analytics/remote_realm_details.html" %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
{{ csrf_input }}
|
{{ csrf_input }}
|
||||||
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
||||||
<select name="sponsorship_pending">
|
<select name="sponsorship_pending">
|
||||||
<option value="true" {% if customer and customer.sponsorship_pending %}selected{% endif %}>Yes</option>
|
<option value="true" {% if sponsorship_data.sponsorship_pending %}selected{% endif %}>Yes</option>
|
||||||
<option value="false" {% if not customer or not customer.sponsorship_pending %}selected{% endif %}>No</option>
|
<option value="false" {% if not sponsorship_data.sponsorship_pending %}selected{% endif %}>No</option>
|
||||||
</select>
|
</select>
|
||||||
<button type="submit" class="btn btn-default support-submit-button">Update</button>
|
<button type="submit" class="btn btn-default support-submit-button">Update</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
{% if customer and customer.sponsorship_pending %}
|
{% if sponsorship_data.sponsorship_pending %}
|
||||||
<form method="POST" class="">
|
<form method="POST" class="">
|
||||||
{{ csrf_input }}
|
{{ csrf_input }}
|
||||||
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
||||||
|
@ -25,10 +25,10 @@
|
||||||
{{ csrf_input }}
|
{{ csrf_input }}
|
||||||
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
<input type="hidden" name="{{ remote_type }}" value="{{ remote_id }}" />
|
||||||
{% if has_fixed_price %}
|
{% if has_fixed_price %}
|
||||||
<input type="number" name="discount" value="{{ get_discount(customer) }}" disabled />
|
<input type="number" name="discount" value="{{ sponsorship_data.default_discount }}" disabled />
|
||||||
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
|
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="number" name="discount" value="{{ get_discount(customer) }}" required />
|
<input type="number" name="discount" value="{{ sponsorship_data.default_discount }}" required />
|
||||||
<button type="submit" class="btn btn-default support-submit-button">Update</button>
|
<button type="submit" class="btn btn-default support-submit-button">Update</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue