From ea725aaaf3c5da094ac7a925f7d241a91cba927d Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Wed, 6 Dec 2023 18:16:20 +0100 Subject: [PATCH] support: Handle missing current licenses data for support views. --- corporate/lib/support.py | 7 ++++++- templates/analytics/current_plan_details.html | 6 ++++++ web/styles/portico/activity.css | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/corporate/lib/support.py b/corporate/lib/support.py index 26775db226..4653703141 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -10,6 +10,7 @@ from django.utils.timezone import now as timezone_now from corporate.lib.stripe import BillingSession from corporate.models import Customer, CustomerPlan, get_current_plan_by_customer from zerver.models import Realm, get_realm +from zilencer.lib.remote_counts import MissingDataError @dataclass @@ -19,6 +20,7 @@ class PlanData: licenses: Optional[int] = None licenses_used: Optional[int] = None is_legacy_plan: bool = False + warning: Optional[str] = None def get_support_url(realm: Realm) -> str: @@ -55,7 +57,10 @@ def get_current_plan_data_for_support_view(billing_session: BillingSession) -> P if new_plan is not None: plan_data.current_plan = new_plan # nocoverage plan_data.licenses = last_ledger_entry.licenses - plan_data.licenses_used = billing_session.current_count_for_billed_licenses() + try: + plan_data.licenses_used = billing_session.current_count_for_billed_licenses() + except MissingDataError: # nocoverage + plan_data.warning = "Recent data missing: No information for used licenses" assert plan_data.current_plan is not None # for mypy plan_data.is_legacy_plan = ( plan_data.current_plan.tier == CustomerPlan.TIER_SELF_HOSTED_LEGACY diff --git a/templates/analytics/current_plan_details.html b/templates/analytics/current_plan_details.html index d123670915..c25b099524 100644 --- a/templates/analytics/current_plan_details.html +++ b/templates/analytics/current_plan_details.html @@ -1,4 +1,10 @@

📅 Current plan information:

+{% if plan_data.warning %} +
+ {{ plan_data.warning }} +
+
+{% endif %} Plan name: {{ plan_data.current_plan.name }}
Status: {{ plan_data.current_plan.get_plan_status_as_text() }}
{% if plan_data.is_legacy_plan %} diff --git a/web/styles/portico/activity.css b/web/styles/portico/activity.css index 12e99c1bfe..cbc9a8bb76 100644 --- a/web/styles/portico/activity.css +++ b/web/styles/portico/activity.css @@ -85,6 +85,7 @@ tr.admin td:first-child { color: hsl(120deg 100% 33%); } +.current-plan-data-missing, .bad { font-weight: bold; color: hsl(0deg 100% 39%);