mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
portico: Fix broken electron check condition for password reset.
This logic for passing through whether the user was logged in never worked, because we were trying to read the client. Fix this, and add tests to ensure it never breaks again. Restructured by tabbott to have completely different code with the same intent. Fixes #11802.
This commit is contained in:
@@ -11,6 +11,7 @@ from zproject.backends import (
|
||||
auth_enabled_helper,
|
||||
AUTH_BACKEND_NAME_MAP,
|
||||
)
|
||||
from zerver.decorator import get_client_name
|
||||
from zerver.lib.bugdown import convert as bugdown_convert
|
||||
from zerver.lib.send_email import FromAddress
|
||||
from zerver.lib.subdomains import get_subdomain
|
||||
@@ -94,10 +95,10 @@ def zulip_default_context(request: HttpRequest) -> Dict[str, Any]:
|
||||
settings_path = "/etc/zulip/settings.py"
|
||||
settings_comments_path = "/etc/zulip/settings.py"
|
||||
|
||||
if hasattr(request, "client") and request.client.name == "ZulipElectron":
|
||||
platform = "ZulipElectron" # nocoverage
|
||||
else:
|
||||
platform = "ZulipWeb"
|
||||
# We can't use request.client here because we might not be using
|
||||
# an auth decorator that sets it, but we can call its helper to
|
||||
# get the same result.
|
||||
platform = get_client_name(request, True)
|
||||
|
||||
context = {
|
||||
'root_domain_landing_page': settings.ROOT_DOMAIN_LANDING_PAGE,
|
||||
|
@@ -184,6 +184,14 @@ class DocPageTest(ZulipTestCase):
|
||||
result = self.client_get('/integrations/doc-html/nonexistent_integration', follow=True)
|
||||
self.assertEqual(result.status_code, 404)
|
||||
|
||||
def test_electron_detection(self) -> None:
|
||||
result = self.client_get("/accounts/password/reset/")
|
||||
self.assertTrue('data-platform="website"' in result.content.decode("utf-8"))
|
||||
|
||||
result = self.client_get("/accounts/password/reset/",
|
||||
HTTP_USER_AGENT="ZulipElectron/1.0.0")
|
||||
self.assertTrue('data-platform="ZulipElectron"' in result.content.decode("utf-8"))
|
||||
|
||||
class HelpTest(ZulipTestCase):
|
||||
def test_help_settings_links(self) -> None:
|
||||
result = self.client_get('/help/change-the-time-format')
|
||||
|
Reference in New Issue
Block a user