compatibility: Clean up linter logic for too-old client.

This commit is contained in:
Tim Abbott 2018-12-05 15:03:42 -08:00
parent 32c6b81b3a
commit 9de1bd44e2
2 changed files with 5 additions and 7 deletions

View File

@ -499,11 +499,6 @@ def build_custom_checkers(by_lang):
'bad_lines': ['return json_error(_variable)', 'return json_error(_(variable))']},
{'pattern': r'''\Wjson_error\(['"].+[),]$''',
'exclude': set(['zerver/tests']),
'exclude_line': set([
# We don't want this string tagged for translation.
('zerver/views/compatibility.py', 'return json_error("Client is too old") # take 0'),
('zerver/views/compatibility.py', 'return json_error("Client is too old")'),
]),
'description': 'Argument to json_error should a literal string enclosed by _()'},
# To avoid JsonableError(_variable) and JsonableError(_(variable))
{'pattern': r'\WJsonableError\(_\(?\w.+\)',

View File

@ -71,12 +71,15 @@ def find_mobile_os(user_agent: str) -> Optional[str]:
android_min_app_version = '16.2.96'
def check_global_compatibility(request: HttpRequest) -> HttpResponse:
# This string should not be tagged for translation, since old
# clients are checking for an extra string.
legacy_compatibility_error_message = "Client is too old"
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
if user_agent['name'] == "ZulipInvalid":
return json_error("Client is too old") # take 0
return json_error(legacy_compatibility_error_message)
if user_agent['name'] == "ZulipMobile":
user_os = find_mobile_os(request.META["HTTP_USER_AGENT"])
if (user_os == 'android'
and version_lt(user_agent['version'], android_min_app_version)):
return json_error("Client is too old")
return json_error(legacy_compatibility_error_message)
return json_success()