From 5cecbcdfb35c16389b3f44a8b47c6564f27ca403 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Tue, 5 Mar 2024 15:42:09 +0100 Subject: [PATCH] config_error: Support passing arguments specifying the "go back" link. Depending on the kind of config error being shown, different "go back" links may be more appropriate. We probably hard-coded /login/ for it, because these config errors are most commonly used for authentication backend config error, where it makes sense to have /login/ as "go back", because the user most likely indeed got there from the login page. However, for remote_billing_bouncer_not_configured, it doesn't make sense, because the user almost surely is already logged in and got there by clicking "Plan management" inside the gear menu in the logged in app. (cherry picked from commit fcc3d88daf2b60800b1ae8a56fa5897beda2338e) --- templates/zerver/config_error/container.html | 2 +- zerver/views/errors.py | 12 +++++++++++- zerver/views/push_notifications.py | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/templates/zerver/config_error/container.html b/templates/zerver/config_error/container.html index 7d07c29715..05aa286098 100644 --- a/templates/zerver/config_error/container.html +++ b/templates/zerver/config_error/container.html @@ -22,7 +22,7 @@

After making your changes, remember to restart the Zulip server.

-

Refresh to try again or click here to go back to the login page.

+

Refresh to try again or go back to {{ go_back_to_url_name }}.

diff --git a/zerver/views/errors.py b/zerver/views/errors.py index 6293811680..3a745ad29e 100644 --- a/zerver/views/errors.py +++ b/zerver/views/errors.py @@ -1,12 +1,22 @@ +from typing import Optional + from django.conf import settings from django.http import HttpRequest, HttpResponse from django.shortcuts import render -def config_error(request: HttpRequest, error_name: str) -> HttpResponse: +def config_error( + request: HttpRequest, + error_name: str, + *, + go_back_to_url: Optional[str] = None, + go_back_to_url_name: Optional[str] = None, +) -> HttpResponse: assert "/" not in error_name context = { "error_name": error_name, + "go_back_to_url": go_back_to_url or "/login/", + "go_back_to_url_name": go_back_to_url_name or "the login page", } if settings.DEVELOPMENT: context["auth_settings_path"] = "zproject/dev-secrets.conf" diff --git a/zerver/views/push_notifications.py b/zerver/views/push_notifications.py index 9308ed4474..18048df994 100644 --- a/zerver/views/push_notifications.py +++ b/zerver/views/push_notifications.py @@ -234,4 +234,9 @@ def self_hosting_auth_not_configured(request: HttpRequest) -> HttpResponse: # is actually real. return render(request, "404.html", status=404) - return config_error(request, "remote_billing_bouncer_not_configured") + return config_error( + request, + "remote_billing_bouncer_not_configured", + go_back_to_url="/", + go_back_to_url_name="the app", + )