mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
realm_redirect: Redirect always to the login page with the next parameter.
Previously, entering an organization via 'accounts/go' with the web-public stream enabled took the user to the web-public view even if the user was not logged in. Now, a user is always redirected to the 'login_page' with the next parameter, if present. The 'login_page' view is updated to redirect an authenticated user based on the 'next' parameter instead of always redirecting to 'realm.uri'. Fixes #23344.
This commit is contained in:
committed by
Tim Abbott
parent
13545ff885
commit
c8a9c0ee04
@@ -1051,7 +1051,7 @@ class LoginTest(ZulipTestCase):
|
||||
"""
|
||||
self.login("cordelia")
|
||||
response = self.client_get("/login/")
|
||||
self.assertEqual(response["Location"], "http://zulip.testserver")
|
||||
self.assertEqual(response["Location"], "http://zulip.testserver/")
|
||||
|
||||
def test_options_request_to_login_page(self) -> None:
|
||||
response = self.client_options("/login/")
|
||||
@@ -1069,7 +1069,7 @@ class LoginTest(ZulipTestCase):
|
||||
self.login_2fa(user_profile)
|
||||
|
||||
response = self.client_get("/login/")
|
||||
self.assertEqual(response["Location"], "http://zulip.testserver")
|
||||
self.assertEqual(response["Location"], "http://zulip.testserver/")
|
||||
|
||||
def test_start_two_factor_auth(self) -> None:
|
||||
request = HostRequestMock()
|
||||
@@ -3964,6 +3964,14 @@ class TestLoginPage(ZulipTestCase):
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(result["Location"], "/accounts/go/?next=%2Fupgrade%2F")
|
||||
|
||||
def test_login_page_redirects_using_next_when_already_authenticated(self) -> None:
|
||||
hamlet = self.example_user("hamlet")
|
||||
self.login("hamlet")
|
||||
|
||||
result = self.client_get("/login/", {"next": "/upgrade/"})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(result["Location"], f"{hamlet.realm.uri}/upgrade/")
|
||||
|
||||
@patch("django.http.HttpRequest.get_host")
|
||||
def test_login_page_works_without_subdomains(self, mock_get_host: MagicMock) -> None:
|
||||
mock_get_host.return_value = "www.testserver"
|
||||
@@ -4229,7 +4237,7 @@ class TwoFactorAuthTest(ZulipTestCase):
|
||||
# Going to login page should redirect to '/' if user is already
|
||||
# logged in.
|
||||
result = self.client_get("/accounts/login/")
|
||||
self.assertEqual(result["Location"], "http://zulip.testserver")
|
||||
self.assertEqual(result["Location"], "http://zulip.testserver/")
|
||||
|
||||
|
||||
class NameRestrictionsTest(ZulipTestCase):
|
||||
@@ -4244,7 +4252,7 @@ class RealmRedirectTest(ZulipTestCase):
|
||||
|
||||
result = self.client_post("/accounts/go/", {"subdomain": "zephyr"})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(result["Location"], "http://zephyr.testserver")
|
||||
self.assertEqual(result["Location"], "http://zephyr.testserver/login/")
|
||||
|
||||
result = self.client_post("/accounts/go/", {"subdomain": "invalid"})
|
||||
self.assert_in_success_response(["We couldn't find that Zulip organization."], result)
|
||||
@@ -4257,4 +4265,4 @@ class RealmRedirectTest(ZulipTestCase):
|
||||
|
||||
result = self.client_post("/accounts/go/?next=billing", {"subdomain": "lear"})
|
||||
self.assertEqual(result.status_code, 302)
|
||||
self.assertEqual(result["Location"], "http://lear.testserver/billing")
|
||||
self.assertEqual(result["Location"], "http://lear.testserver/login/?next=billing")
|
||||
|
||||
Reference in New Issue
Block a user