From 7a40462aed7e4711cb02e2c52396e02b2e5189e3 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Mon, 2 Dec 2024 18:25:24 +0100 Subject: [PATCH] support: Use datetime for push notification data in remote support. --- corporate/lib/support.py | 29 +++++++++++++++---- .../support/push_status_details.html | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/corporate/lib/support.py b/corporate/lib/support.py index c013bc8887..34fef3756f 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -7,7 +7,6 @@ from django.utils.timezone import now as timezone_now from corporate.lib.stripe import ( BillingSession, - PushNotificationsEnabledStatus, RealmBillingSession, RemoteRealmBillingSession, RemoteServerBillingSession, @@ -25,6 +24,7 @@ from corporate.models import ( ZulipSponsorshipRequest, get_current_plan_by_customer, ) +from zerver.lib.timestamp import timestamp_to_datetime from zerver.models import Realm from zerver.models.realm_audit_logs import AuditLogEventType from zerver.models.realms import get_org_type_display_name @@ -91,10 +91,17 @@ class PlanData: estimated_next_plan_revenue: int | None = None +@dataclass +class PushNotificationsStatus: + can_push: bool + expected_end: datetime | None + message: str + + @dataclass class MobilePushData: total_mobile_users: int - push_notification_status: PushNotificationsEnabledStatus + push_notification_status: PushNotificationsStatus uncategorized_mobile_users: int | None = None mobile_pushes_forwarded: int | None = None last_mobile_push_sent: str = "" @@ -350,9 +357,16 @@ def get_mobile_push_data(remote_entity: RemoteZulipServer | RemoteRealm) -> Mobi ).strftime("%Y-%m-%d") else: push_forwarded_interval_start = "None" - push_notification_status = get_push_status_for_remote_request( + push_status = get_push_status_for_remote_request( remote_server=remote_entity, remote_realm=None ) + push_notification_status = PushNotificationsStatus( + can_push=push_status.can_push, + expected_end=timestamp_to_datetime(push_status.expected_end_timestamp) + if push_status.expected_end_timestamp + else None, + message=push_status.message, + ) return MobilePushData( total_mobile_users=total_users, push_notification_status=push_notification_status, @@ -386,8 +400,13 @@ def get_mobile_push_data(remote_entity: RemoteZulipServer | RemoteRealm) -> Mobi ).strftime("%Y-%m-%d") else: push_forwarded_interval_start = "None" - push_notification_status = get_push_status_for_remote_request( - remote_entity.server, remote_entity + push_status = get_push_status_for_remote_request(remote_entity.server, remote_entity) + push_notification_status = PushNotificationsStatus( + can_push=push_status.can_push, + expected_end=timestamp_to_datetime(push_status.expected_end_timestamp) + if push_status.expected_end_timestamp + else None, + message=push_status.message, ) return MobilePushData( total_mobile_users=mobile_users, diff --git a/templates/corporate/support/push_status_details.html b/templates/corporate/support/push_status_details.html index e0df02be48..dcb67e4b94 100644 --- a/templates/corporate/support/push_status_details.html +++ b/templates/corporate/support/push_status_details.html @@ -1,6 +1,6 @@

📶 Push notification status:

Can push: {{ status.can_push }}
- Expected end: {{ format_optional_datetime(status.expected_end_timestamp, True) }}
+ Expected end: {{ format_optional_datetime(status.expected_end, True) }}
Message: {{ status.message }}