corporate: Show error page if mobile push data has not been uploaded.

Adds a template that displays an error message when the billing
or upgrade context for a remote server or remote realm raises a
MissingDataError.
This commit is contained in:
Lauryn Menard 2023-12-07 15:27:39 +01:00 committed by Tim Abbott
parent e9ce69aaf6
commit aebafcc43f
4 changed files with 88 additions and 4 deletions

View File

@ -17,6 +17,8 @@ from django.conf import settings
from django.core import signing from django.core import signing
from django.core.signing import Signer from django.core.signing import Signer
from django.db import transaction from django.db import transaction
from django.http import HttpRequest, HttpResponse
from django.shortcuts import render
from django.urls import reverse from django.urls import reverse
from django.utils.timezone import now as timezone_now from django.utils.timezone import now as timezone_now
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
@ -3029,6 +3031,19 @@ class RemoteRealmBillingSession(BillingSession): # nocoverage
) )
return remote_realm_counts.non_guest_user_count + remote_realm_counts.guest_user_count return remote_realm_counts.non_guest_user_count + remote_realm_counts.guest_user_count
def missing_data_error_page(self, request: HttpRequest) -> HttpResponse:
# The RemoteRealm error page code path should not really be
# possible, in that the self-hosted server will have uploaded
# current audit log data as needed as part of logging the user
# in.
missing_data_context: Dict[str, Any] = {
"remote_realm_session": True,
"supports_remote_realms": self.remote_realm.server.last_api_feature_level is not None,
}
return render(
request, "corporate/server_not_uploading_data.html", context=missing_data_context
)
@override @override
def get_audit_log_event(self, event_type: AuditLogEventType) -> int: def get_audit_log_event(self, event_type: AuditLogEventType) -> int:
if event_type is AuditLogEventType.STRIPE_CUSTOMER_CREATED: if event_type is AuditLogEventType.STRIPE_CUSTOMER_CREATED:
@ -3407,6 +3422,17 @@ class RemoteServerBillingSession(BillingSession): # nocoverage
) )
return remote_server_counts.non_guest_user_count + remote_server_counts.guest_user_count return remote_server_counts.non_guest_user_count + remote_server_counts.guest_user_count
def missing_data_error_page(self, request: HttpRequest) -> HttpResponse:
# The remedy for a RemoteZulipServer login is usually
# upgrading to Zulip 8.0 or enabling SUBMIT_USAGE_STATISTICS.
missing_data_context = {
"remote_realm_session": False,
"supports_remote_realms": self.remote_server.last_api_feature_level is not None,
}
return render(
request, "corporate/server_not_uploading_data.html", context=missing_data_context
)
@override @override
def get_audit_log_event(self, event_type: AuditLogEventType) -> int: def get_audit_log_event(self, event_type: AuditLogEventType) -> int:
if event_type is AuditLogEventType.STRIPE_CUSTOMER_CREATED: if event_type is AuditLogEventType.STRIPE_CUSTOMER_CREATED:

View File

@ -25,6 +25,7 @@ from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import typed_endpoint from zerver.lib.typed_endpoint import typed_endpoint
from zerver.lib.validator import check_int, check_int_in from zerver.lib.validator import check_int, check_int_in
from zerver.models import UserProfile from zerver.models import UserProfile
from zilencer.lib.remote_counts import MissingDataError
from zilencer.models import RemoteRealm, RemoteZulipServer from zilencer.models import RemoteRealm, RemoteZulipServer
billing_logger = logging.getLogger("corporate.stripe") billing_logger = logging.getLogger("corporate.stripe")
@ -130,7 +131,11 @@ def remote_realm_billing_page(
): ):
return HttpResponseRedirect(reverse("remote_realm_plans_page", args=(realm_uuid,))) return HttpResponseRedirect(reverse("remote_realm_plans_page", args=(realm_uuid,)))
try:
main_context = billing_session.get_billing_page_context() main_context = billing_session.get_billing_page_context()
except MissingDataError:
return billing_session.missing_data_error_page(request)
if main_context: if main_context:
context.update(main_context) context.update(main_context)
context["success_message"] = success_message context["success_message"] = success_message
@ -190,7 +195,11 @@ def remote_server_billing_page(
) )
) )
try:
main_context = billing_session.get_billing_page_context() main_context = billing_session.get_billing_page_context()
except MissingDataError:
return billing_session.missing_data_error_page(request)
if main_context: if main_context:
context.update(main_context) context.update(main_context)
context["success_message"] = success_message context["success_message"] = success_message

View File

@ -28,6 +28,7 @@ from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import typed_endpoint from zerver.lib.typed_endpoint import typed_endpoint
from zerver.lib.validator import check_bool, check_int, check_string_in from zerver.lib.validator import check_bool, check_int, check_string_in
from zerver.models import UserProfile from zerver.models import UserProfile
from zilencer.lib.remote_counts import MissingDataError
billing_logger = logging.getLogger("corporate.stripe") billing_logger = logging.getLogger("corporate.stripe")
@ -220,7 +221,10 @@ def remote_realm_upgrade_page(
tier=CustomerPlan.TIER_SELF_HOSTED_BUSINESS, tier=CustomerPlan.TIER_SELF_HOSTED_BUSINESS,
success_message=success_message, success_message=success_message,
) )
try:
redirect_url, context = billing_session.get_initial_upgrade_context(initial_upgrade_request) redirect_url, context = billing_session.get_initial_upgrade_context(initial_upgrade_request)
except MissingDataError:
return billing_session.missing_data_error_page(request)
if redirect_url: if redirect_url:
return HttpResponseRedirect(redirect_url) return HttpResponseRedirect(redirect_url)
@ -243,7 +247,10 @@ def remote_server_upgrade_page(
tier=CustomerPlan.TIER_SELF_HOSTED_BUSINESS, tier=CustomerPlan.TIER_SELF_HOSTED_BUSINESS,
success_message=success_message, success_message=success_message,
) )
try:
redirect_url, context = billing_session.get_initial_upgrade_context(initial_upgrade_request) redirect_url, context = billing_session.get_initial_upgrade_context(initial_upgrade_request)
except MissingDataError:
return billing_session.missing_data_error_page(request)
if redirect_url: if redirect_url:
return HttpResponseRedirect(redirect_url) return HttpResponseRedirect(redirect_url)

View File

@ -0,0 +1,42 @@
{% extends "zerver/portico.html" %}
{% block title %}
<title>Required metadata missing | Zulip</title>
{% endblock %}
{% block portico_content %}
<div class="center-block flex full-page account-creation new-style">
<div class="inline-block">
<div class="get-started">
<h1>Error: Server not uploading basic metadata</h1>
</div>
<div class="white-box">
<p>
Managing your Zulip plan requires your server to upload
up-to-date
<a
href="https://zulip.readthedocs.io/en/latest/production/mobile-push-notifications.html#uploading-basic-metadata">basic
metadata</a>. This data is not being uploaded successfully.
</p>
{% if remote_realm_session %}
<p>
If your Zulip server's administrator is not able to fix this, <a
href="mailto:support@zulip.com">contact Zulip support</a>.
</p>
{% elif supports_remote_realms %}
<p>
If your Zulip server's administrator is not able to fix this, <a
href="mailto:support@zulip.com">contact Zulip support</a>.
</p>
{% else %}
<p>
Your Zulip server's administrator can fix this issue by <a
href="https://zulip.readthedocs.io/en/stable/production/upgrade.html">upgrading</a>
the server to Zulip 8.0+, or enabling the
<code>SUBMIT_USAGE_STATISTICS</code> setting.
</p>
{% endif %}
</div>
</div>
</div>
{% endblock %}