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 fcc3d88daf)
This commit is contained in:
Mateusz Mandera 2024-03-05 15:42:09 +01:00 committed by Tim Abbott
parent 7d0917c3c7
commit 5cecbcdfb3
3 changed files with 18 additions and 3 deletions

View File

@ -22,7 +22,7 @@
<p>After making your changes, remember to restart
the Zulip server.</p>
<p><a href=""> Refresh</a> to try again or <a href="/login/">click here</a> to go back to the login page.</p>
<p><a href=""> Refresh</a> to try again or <a href="{{ go_back_to_url }}">go back to {{ go_back_to_url_name }}</a>.</p>
</div>
</div>

View File

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

View File

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