2020-06-11 00:54:34 +02:00
|
|
|
from django.http import HttpRequest, HttpResponse
|
2021-04-16 00:57:30 +02:00
|
|
|
from django.utils.translation import gettext as _
|
2018-12-10 22:42:28 +01:00
|
|
|
|
2021-06-04 10:19:50 +02:00
|
|
|
from zerver.lib.compatibility import find_mobile_os, version_lt
|
2021-06-30 18:35:50 +02:00
|
|
|
from zerver.lib.exceptions import JsonableError
|
|
|
|
from zerver.lib.response import json_success
|
2017-01-30 07:21:13 +01:00
|
|
|
from zerver.lib.user_agent import parse_user_agent
|
2018-12-05 00:46:52 +01:00
|
|
|
|
2018-12-05 00:49:23 +01:00
|
|
|
# Zulip Mobile release 16.2.96 was made 2018-08-22. It fixed a
|
|
|
|
# bug in our Android code that causes spammy, obviously-broken
|
|
|
|
# notifications once the "remove_push_notification" feature is
|
|
|
|
# enabled on the user's Zulip server.
|
2021-02-12 08:20:45 +01:00
|
|
|
android_min_app_version = "16.2.96"
|
2018-12-05 00:49:23 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2018-11-29 03:07:40 +01:00
|
|
|
def check_global_compatibility(request: HttpRequest) -> HttpResponse:
|
2021-02-12 08:20:45 +01:00
|
|
|
if request.META.get("HTTP_USER_AGENT") is None:
|
2021-06-30 18:35:50 +02:00
|
|
|
raise JsonableError(_("User-Agent header missing from request"))
|
2018-12-10 22:42:28 +01:00
|
|
|
|
2018-12-06 00:03:42 +01:00
|
|
|
# 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"
|
2017-01-30 07:21:13 +01:00
|
|
|
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
|
2021-02-12 08:20:45 +01:00
|
|
|
if user_agent["name"] == "ZulipInvalid":
|
2021-06-30 18:35:50 +02:00
|
|
|
raise JsonableError(legacy_compatibility_error_message)
|
2021-02-12 08:20:45 +01:00
|
|
|
if user_agent["name"] == "ZulipMobile":
|
2018-12-05 00:49:23 +01:00
|
|
|
user_os = find_mobile_os(request.META["HTTP_USER_AGENT"])
|
2021-02-12 08:20:45 +01:00
|
|
|
if user_os == "android" and version_lt(user_agent["version"], android_min_app_version):
|
2021-06-30 18:35:50 +02:00
|
|
|
raise JsonableError(legacy_compatibility_error_message)
|
2017-01-30 07:21:13 +01:00
|
|
|
return json_success()
|