Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
decorator: Unfork redirect_to_login.
Anders Kaseorg96dee7e40b4a
diff --git a/zerver/decorator.py b/zerver/decorator.pyindex 3b55eaa4c5d..be23241876c 100644--- a/zerver/decorator.py+++ b/zerver/decorator.py@@ -12,6 +12,7 @@ from django.contrib.auth import REDIRECT_FIELD_NAMEfrom django.contrib.auth import login as django_loginfrom django.contrib.auth.decorators import user_passes_test as django_user_passes_testfrom django.contrib.auth.models import AnonymousUser+from django.contrib.auth.views import redirect_to_loginfrom django.http import HttpRequest, HttpResponse, HttpResponseRedirect, QueryDictfrom django.http.multipartparser import MultiPartParserfrom django.shortcuts import resolve_url@@ -313,24 +314,6 @@ def webhook_view(return _wrapped_func_argumentsreturn _wrapped_view_func-# From Django 1.8, modified to leave off ?next=/-def redirect_to_login(next: str, login_url: Optional[str]=None,- redirect_field_name: str=REDIRECT_FIELD_NAME) -> HttpResponseRedirect:- """- Redirects the user to the login page, passing the given 'next' page- """- resolved_url = resolve_url(login_url or settings.LOGIN_URL)-- login_url_parts = list(urllib.parse.urlparse(resolved_url))- if redirect_field_name:- querystring = QueryDict(login_url_parts[4], mutable=True)- querystring[redirect_field_name] = next- # Don't add ?next=/, to keep our URLs clean- if next != '/':- login_url_parts[4] = querystring.urlencode(safe='/')-- return HttpResponseRedirect(urllib.parse.urlunparse(login_url_parts))-# From Django 2.2, modified to pass the request rather than just the# user into test_func; this is useful so that we can revalidate the# subdomain matches the user's realm. It is likely that we could make@@ -357,6 +340,10 @@ def user_passes_test(test_func: Callable[[HttpResponse], bool], login_url: Optioif ((not login_scheme or login_scheme == current_scheme) and(not login_netloc or login_netloc == current_netloc)):path = request.get_full_path()++ if path == "/":+ # Don't add ?next=/, to keep our URLs clean+ return HttpResponseRedirect(resolved_login_url)return redirect_to_login(path, resolved_login_url, redirect_field_name)return cast(ViewFuncT, _wrapped_view) # https://github.com/python/mypy/issues/1927diff --git a/zerver/views/portico.py b/zerver/views/portico.pyindex 47709a11927..8189b730151 100644--- a/zerver/views/portico.py+++ b/zerver/views/portico.py@@ -2,12 +2,13 @@ from typing import Optionalimport orjsonfrom django.conf import settings+from django.contrib.auth.views import redirect_to_loginfrom django.http import HttpRequest, HttpResponse, HttpResponseRedirectfrom django.template.response import TemplateResponsefrom version import LATEST_DESKTOP_VERSIONfrom zerver.context_processors import get_realm_from_request, latest_info_context-from zerver.decorator import add_google_analytics, redirect_to_login+from zerver.decorator import add_google_analyticsfrom zerver.models import Realm