support: Add user count data to remote support view.

This commit is contained in:
Lauryn Menard 2023-12-15 18:04:08 +01:00 committed by Tim Abbott
parent a8172591ca
commit fb3bd0cde1
3 changed files with 22 additions and 2 deletions

View File

@ -7,7 +7,11 @@ from django.conf import settings
from django.urls import reverse
from django.utils.timezone import now as timezone_now
from corporate.lib.stripe import BillingSession
from corporate.lib.stripe import (
BillingSession,
RemoteRealmBillingSession,
RemoteServerBillingSession,
)
from corporate.models import (
Customer,
CustomerPlan,
@ -17,6 +21,11 @@ from corporate.models import (
from zerver.models import Realm
from zerver.models.realms import get_org_type_display_name, get_realm
from zilencer.lib.remote_counts import MissingDataError
from zilencer.models import (
RemoteCustomerUserCount,
get_remote_realm_guest_and_non_guest_count,
get_remote_server_guest_and_non_guest_count,
)
class SponsorshipRequestDict(TypedDict):
@ -51,6 +60,7 @@ class PlanData:
class SupportData:
plan_data: PlanData
sponsorship_data: SponsorshipData
user_data: RemoteCustomerUserCount
def get_realm_support_url(realm: Realm) -> str:
@ -135,6 +145,11 @@ def get_current_plan_data_for_support_view(billing_session: BillingSession) -> P
def get_data_for_support_view(billing_session: BillingSession) -> SupportData:
if isinstance(billing_session, RemoteServerBillingSession):
user_data = get_remote_server_guest_and_non_guest_count(billing_session.remote_server.id)
else: # nocoverage
assert isinstance(billing_session, RemoteRealmBillingSession)
user_data = get_remote_realm_guest_and_non_guest_count(billing_session.remote_realm)
plan_data = get_current_plan_data_for_support_view(billing_session)
customer = billing_session.get_customer()
if customer is not None:
@ -145,4 +160,5 @@ def get_data_for_support_view(billing_session: BillingSession) -> SupportData:
return SupportData(
plan_data=plan_data,
sponsorship_data=sponsorship_data,
user_data=user_data,
)

View File

@ -11,6 +11,8 @@
<b>Date created</b>: {{ remote_realm.realm_date_created.strftime('%d %B %Y') }}<br />
<b>Org type</b>: {{ get_org_type_display_name(remote_realm.org_type) }}<br />
<b>Plan type</b>: {{ get_plan_type_name(remote_realm.plan_type) }}<br />
<b>Non-guest user count</b>: {{ support_data[remote_realm.id].user_data.non_guest_user_count }}<br />
<b>Guest user count</b>: {{ support_data[remote_realm.id].user_data.guest_user_count }}<br />
</div>
{% if remote_realm.plan_type != SPONSORED_PLAN_TYPE %}

View File

@ -52,7 +52,9 @@
<b>Last updated</b>: {{ remote_server.last_updated|timesince }} ago<br />
<b>Max monthly messages</b>: {{ remote_server_to_max_monthly_messages[remote_server.id] }}<br />
<b>Plan type</b>: {{ get_plan_type_name(remote_server.plan_type) }}<br />
<b>Has remote realm(s)</b>: {{ remote_realms[remote_server.id] != [] }}
<b>Has remote realm(s)</b>: {{ remote_realms[remote_server.id] != [] }}<br />
<b>Non-guest user count</b>: {{ remote_servers_support_data[remote_server.id].user_data.non_guest_user_count }}<br />
<b>Guest user count</b>: {{ remote_servers_support_data[remote_server.id].user_data.guest_user_count }}<br />
</div>
{% if remote_server.plan_type != SPONSORED_PLAN_TYPE %}