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.
This commit is contained in:
Lauryn Menard 2024-02-23 16:51:51 +01:00 committed by Tim Abbott
parent 423af9916a
commit e4e65074df
6 changed files with 45 additions and 3 deletions

View File

@ -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,

View File

@ -174,6 +174,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
"<b>Plan type</b>: Free<br />",
"<b>Non-guest user count</b>: 0<br />",
"<b>Guest user count</b>: 0<br />",
"📶 Push notification status:",
],
html_response,
)
@ -190,6 +191,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
"<b>Date created</b>: 01 December 2023",
"<b>Org type</b>: Unspecified<br />",
"<b>Has remote realms</b>: True<br />",
"📶 Push notification status:",
],
html_response,
)

View File

@ -0,0 +1,6 @@
<div class="push-notification-status">
<p class="support-section-header">📶 Push notification status:</p>
<b>Can push</b>: {{ status.can_push }}<br />
<b>Expected end</b>: {{ format_optional_datetime(status.expected_end_timestamp, True) }}<br />
<b>Message</b>: {{ status.message }}<br />
</div>

View File

@ -29,6 +29,12 @@
<b>Last push notification date</b>: {{ support_data[remote_realm.id].mobile_push_data.last_mobile_push_sent }}<br />
</div>
{% 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 %}
<div class="remote-support-sponsorship-container">
{% with %}

View File

@ -68,6 +68,11 @@
<b>Last push notification date</b>: {{ remote_servers_support_data[remote_server.id].mobile_push_data.last_mobile_push_sent }}<br />
</div>
{% 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 %}
<div class="remote-support-sponsorship-container">
{% with %}

View File

@ -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,