From fb3bd0cde116f2ee38a8ea03cd940263461e578e Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Fri, 15 Dec 2023 18:04:08 +0100 Subject: [PATCH] support: Add user count data to remote support view. --- corporate/lib/support.py | 18 +++++++++++++++++- templates/analytics/remote_realm_details.html | 2 ++ templates/analytics/remote_server_support.html | 4 +++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/corporate/lib/support.py b/corporate/lib/support.py index 4076245993..12b2ddac44 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -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, ) diff --git a/templates/analytics/remote_realm_details.html b/templates/analytics/remote_realm_details.html index 8d6b788fbc..853bf80ebf 100644 --- a/templates/analytics/remote_realm_details.html +++ b/templates/analytics/remote_realm_details.html @@ -11,6 +11,8 @@ Date created: {{ remote_realm.realm_date_created.strftime('%d %B %Y') }}
Org type: {{ get_org_type_display_name(remote_realm.org_type) }}
Plan type: {{ get_plan_type_name(remote_realm.plan_type) }}
+ Non-guest user count: {{ support_data[remote_realm.id].user_data.non_guest_user_count }}
+ Guest user count: {{ support_data[remote_realm.id].user_data.guest_user_count }}
{% if remote_realm.plan_type != SPONSORED_PLAN_TYPE %} diff --git a/templates/analytics/remote_server_support.html b/templates/analytics/remote_server_support.html index 209157cb91..eaedbb01e1 100644 --- a/templates/analytics/remote_server_support.html +++ b/templates/analytics/remote_server_support.html @@ -52,7 +52,9 @@ Last updated: {{ remote_server.last_updated|timesince }} ago
Max monthly messages: {{ remote_server_to_max_monthly_messages[remote_server.id] }}
Plan type: {{ get_plan_type_name(remote_server.plan_type) }}
- Has remote realm(s): {{ remote_realms[remote_server.id] != [] }} + Has remote realm(s): {{ remote_realms[remote_server.id] != [] }}
+ Non-guest user count: {{ remote_servers_support_data[remote_server.id].user_data.non_guest_user_count }}
+ Guest user count: {{ remote_servers_support_data[remote_server.id].user_data.guest_user_count }}
{% if remote_server.plan_type != SPONSORED_PLAN_TYPE %}