mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
billing: Return login URL for AJAX request session timeout for servers.
This commit is contained in:
@@ -2,9 +2,8 @@ from functools import wraps
|
|||||||
from typing import Callable, Optional
|
from typing import Callable, Optional
|
||||||
from urllib.parse import urlencode, urljoin
|
from urllib.parse import urlencode, urljoin
|
||||||
|
|
||||||
import orjson
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, JsonResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from typing_extensions import Concatenate, ParamSpec
|
from typing_extensions import Concatenate, ParamSpec
|
||||||
@@ -23,6 +22,16 @@ from zilencer.models import RemoteRealm
|
|||||||
ParamT = ParamSpec("ParamT")
|
ParamT = ParamSpec("ParamT")
|
||||||
|
|
||||||
|
|
||||||
|
def session_expired_ajax_response(login_url: str) -> JsonResponse: # nocoverage
|
||||||
|
return JsonResponse(
|
||||||
|
{
|
||||||
|
"error_message": "Remote billing authentication expired",
|
||||||
|
"login_url": login_url,
|
||||||
|
},
|
||||||
|
status=401,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_self_hosting_management_subdomain(request: HttpRequest) -> bool:
|
def is_self_hosting_management_subdomain(request: HttpRequest) -> bool:
|
||||||
subdomain = get_subdomain(request)
|
subdomain = get_subdomain(request)
|
||||||
return subdomain == settings.SELF_HOSTING_MANAGEMENT_SUBDOMAIN
|
return subdomain == settings.SELF_HOSTING_MANAGEMENT_SUBDOMAIN
|
||||||
@@ -107,15 +116,7 @@ def authenticated_remote_realm_management_endpoint(
|
|||||||
|
|
||||||
# Return error for AJAX requests with url.
|
# Return error for AJAX requests with url.
|
||||||
if request.headers.get("x-requested-with") == "XMLHttpRequest": # nocoverage
|
if request.headers.get("x-requested-with") == "XMLHttpRequest": # nocoverage
|
||||||
return HttpResponse(
|
return session_expired_ajax_response(url)
|
||||||
orjson.dumps(
|
|
||||||
{
|
|
||||||
"error_message": "Remote billing authentication expired",
|
|
||||||
"login_url": url,
|
|
||||||
}
|
|
||||||
),
|
|
||||||
status=401,
|
|
||||||
)
|
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
@@ -187,6 +188,10 @@ def authenticated_remote_server_management_endpoint(
|
|||||||
query = urlencode({"next_page": page_type})
|
query = urlencode({"next_page": page_type})
|
||||||
url = append_url_query_string(url, query)
|
url = append_url_query_string(url, query)
|
||||||
|
|
||||||
|
# Return error for AJAX requests with url.
|
||||||
|
if request.headers.get("x-requested-with") == "XMLHttpRequest": # nocoverage
|
||||||
|
return session_expired_ajax_response(url)
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
assert remote_billing_user is not None
|
assert remote_billing_user is not None
|
||||||
|
|||||||
Reference in New Issue
Block a user