From 59d2eae946dc7b40cc9c8f74b4efde822baad4c0 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 3 Jul 2017 10:10:50 -0700 Subject: [PATCH] signals: Fix browser reporting for new Electron logins. Previously, we were checking for "Zulip" entries in User-Agent strings at the very end of the list, not the beginning. A Zulip User-Agent should have priority, since it includes the User-Agent strings for a lot of other browsers, and also it will always be the most specific value. --- zerver/signals.py | 6 +++--- zerver/tests/test_new_users.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/zerver/signals.py b/zerver/signals.py index f7e462ef2e..379a9c848d 100644 --- a/zerver/signals.py +++ b/zerver/signals.py @@ -13,7 +13,9 @@ from zerver.models import UserProfile def get_device_browser(user_agent): # type: (str) -> Optional[str] user_agent = user_agent.lower() - if "edge" in user_agent: + if "zulip" in user_agent: + return "Zulip" + elif "edge" in user_agent: return "Edge" elif "opera" in user_agent or "opr/" in user_agent: return "Opera" @@ -27,8 +29,6 @@ def get_device_browser(user_agent): return "Safari" elif "msie" in user_agent or "trident" in user_agent: return "Internet Explorer" - elif "zulip" in user_agent: - return "Zulip" else: return None diff --git a/zerver/tests/test_new_users.py b/zerver/tests/test_new_users.py index d463ff2125..4a1a759e88 100644 --- a/zerver/tests/test_new_users.py +++ b/zerver/tests/test_new_users.py @@ -89,6 +89,9 @@ class TestBrowserAndOsUserAgentStrings(ZulipTestCase): 'Version/10.0.2 Safari/602.3.12', 'Safari', 'MacOS'), ('ZulipAndroid/1.0', 'Zulip', 'Android'), ('ZulipMobile/1.0', 'Zulip', None), + ('ZulipElectron/1.1.0-beta Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' + + 'AppleWebKit/537.36 (KHTML, like Gecko) Zulip/1.1.0-beta ' + + 'Chrome/56.0.2924.87 Electron/1.6.8 Safari/537.36', 'Zulip', 'Windows'), ('Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, ' 'like Gecko) Ubuntu/11.10 Chromium/16.0.912.77 ' 'Chrome/16.0.912.77 Safari/535.7', 'Chromium', 'Linux'),