From e4e65074dfbb782be88164bc40388cdf7c6b818c Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Fri, 23 Feb 2024 16:51:51 +0100 Subject: [PATCH] remote-support: Add push notification status information. Adds the information returned by get_push_status_for_remote_request for remote billing users to the support page. Note that getting the current push status data will result in some duplicate database queries (getting customer, plan, current billed users, next billing cycle) when generating the remote support view. --- corporate/lib/support.py | 11 +++++++++++ corporate/tests/test_support_views.py | 2 ++ .../corporate/support/push_status_details.html | 6 ++++++ .../support/remote_realm_details.html | 6 ++++++ .../support/remote_server_support.html | 5 +++++ web/styles/portico/activity.css | 18 +++++++++++++++--- 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 templates/corporate/support/push_status_details.html diff --git a/corporate/lib/support.py b/corporate/lib/support.py index f0d4b67373..4078c87d00 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -11,9 +11,11 @@ from django.utils.timezone import now as timezone_now from corporate.lib.stripe import ( BillingSession, + PushNotificationsEnabledStatus, RemoteRealmBillingSession, RemoteServerBillingSession, get_configured_fixed_price_plan_offer, + get_push_status_for_remote_request, start_of_next_billing_cycle, ) from corporate.models import ( @@ -86,6 +88,7 @@ class PlanData: @dataclass class MobilePushData: total_mobile_users: int + push_notification_status: PushNotificationsEnabledStatus uncategorized_mobile_users: Optional[int] = None mobile_pushes_forwarded: Optional[int] = None last_mobile_push_sent: str = "" @@ -304,8 +307,12 @@ def get_mobile_push_data(remote_entity: Union[RemoteZulipServer, RemoteRealm]) - ).strftime("%Y-%m-%d") else: push_forwarded_interval_start = "None" + push_notification_status = get_push_status_for_remote_request( + remote_server=remote_entity, remote_realm=None + ) return MobilePushData( total_mobile_users=total_users, + push_notification_status=push_notification_status, uncategorized_mobile_users=uncategorized_users, mobile_pushes_forwarded=mobile_pushes["total_forwarded"], last_mobile_push_sent=push_forwarded_interval_start, @@ -334,8 +341,12 @@ def get_mobile_push_data(remote_entity: Union[RemoteZulipServer, RemoteRealm]) - ).strftime("%Y-%m-%d") else: push_forwarded_interval_start = "None" + push_notification_status = get_push_status_for_remote_request( + remote_entity.server, remote_entity + ) return MobilePushData( total_mobile_users=mobile_users, + push_notification_status=push_notification_status, uncategorized_mobile_users=None, mobile_pushes_forwarded=mobile_pushes["total_forwarded"], last_mobile_push_sent=push_forwarded_interval_start, diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py index f0ad1f4705..50091a0ea1 100644 --- a/corporate/tests/test_support_views.py +++ b/corporate/tests/test_support_views.py @@ -174,6 +174,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): "Plan type: Free
", "Non-guest user count: 0
", "Guest user count: 0
", + "📶 Push notification status:", ], html_response, ) @@ -190,6 +191,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): "Date created: 01 December 2023", "Org type: Unspecified
", "Has remote realms: True
", + "📶 Push notification status:", ], html_response, ) diff --git a/templates/corporate/support/push_status_details.html b/templates/corporate/support/push_status_details.html new file mode 100644 index 0000000000..e0df02be48 --- /dev/null +++ b/templates/corporate/support/push_status_details.html @@ -0,0 +1,6 @@ +
+

📶 Push notification status:

+ Can push: {{ status.can_push }}
+ Expected end: {{ format_optional_datetime(status.expected_end_timestamp, True) }}
+ Message: {{ status.message }}
+
diff --git a/templates/corporate/support/remote_realm_details.html b/templates/corporate/support/remote_realm_details.html index 6e33922202..d8c2cef7f8 100644 --- a/templates/corporate/support/remote_realm_details.html +++ b/templates/corporate/support/remote_realm_details.html @@ -29,6 +29,12 @@ Last push notification date: {{ support_data[remote_realm.id].mobile_push_data.last_mobile_push_sent }}
+ {% with %} + {% set status = support_data[remote_realm.id].mobile_push_data.push_notification_status %} + {% include 'corporate/support/push_status_details.html' %} + {% endwith %} + + {% if remote_realm.plan_type != SPONSORED_PLAN_TYPE %}
{% with %} diff --git a/templates/corporate/support/remote_server_support.html b/templates/corporate/support/remote_server_support.html index b0f5e3f192..93fa7729bb 100644 --- a/templates/corporate/support/remote_server_support.html +++ b/templates/corporate/support/remote_server_support.html @@ -68,6 +68,11 @@ Last push notification date: {{ remote_servers_support_data[remote_server.id].mobile_push_data.last_mobile_push_sent }}
+ {% with %} + {% set status = remote_servers_support_data[remote_server.id].mobile_push_data.push_notification_status %} + {% include 'corporate/support/push_status_details.html' %} + {% endwith %} + {% if remote_server.plan_type != SPONSORED_PLAN_TYPE %}
{% with %} diff --git a/web/styles/portico/activity.css b/web/styles/portico/activity.css index d6804b1a3c..3e26a52b24 100644 --- a/web/styles/portico/activity.css +++ b/web/styles/portico/activity.css @@ -396,14 +396,26 @@ tr.admin td:first-child { padding-bottom: 25px; } +.push-notification-status, +.realm-form-container, +.next-plan-container, +.current-plan-container, +.remote-support-sponsorship-container { + border-radius: 4px; + padding: 10px; + margin: 10px 0; +} + +.push-notification-status { + border: 2px solid hsl(186deg 76% 36%); + background-color: hsl(188deg 35% 87%); +} + .realm-form-container, .next-plan-container, .current-plan-container, .remote-support-sponsorship-container { border: 2px solid hsl(33deg 99% 60%); - border-radius: 4px; - padding: 10px; - margin: 10px 0; } .realm-form-container,