Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

billing: Return login URL for AJAX request session timeout for servers.

Aman Agrawalca96868b0ecd
diff --git a/corporate/lib/decorator.py b/corporate/lib/decorator.py
index bd56c3de771..94d513b7223 100644
--- a/corporate/lib/decorator.py
+++ b/corporate/lib/decorator.py
@@ -2,9 +2,8 @@ from functools import wraps
from typing import Callable, Optional
from urllib.parse import urlencode, urljoin
-import orjson
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.urls import reverse
from typing_extensions import Concatenate, ParamSpec
@@ -23,6 +22,16 @@ from zilencer.models import RemoteRealm
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:
subdomain = get_subdomain(request)
return subdomain == settings.SELF_HOSTING_MANAGEMENT_SUBDOMAIN
@@ -107,15 +116,7 @@ def authenticated_remote_realm_management_endpoint(
# Return error for AJAX requests with url.
if request.headers.get("x-requested-with") == "XMLHttpRequest": # nocoverage
- return HttpResponse(
- orjson.dumps(
- {
- "error_message": "Remote billing authentication expired",
- "login_url": url,
- }
- ),
- status=401,
- )
+ return session_expired_ajax_response(url)
return HttpResponseRedirect(url)
@@ -187,6 +188,10 @@ def authenticated_remote_server_management_endpoint(
query = urlencode({"next_page": page_type})
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)
assert remote_billing_user is not None