mirror of https://github.com/zulip/zulip.git
30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
from django.http import HttpRequest, HttpResponse
|
|
from django.utils.translation import gettext as _
|
|
|
|
from zerver.lib.compatibility import find_mobile_os, version_lt
|
|
from zerver.lib.response import json_error, json_success
|
|
from zerver.lib.user_agent import parse_user_agent
|
|
|
|
# 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.
|
|
android_min_app_version = "16.2.96"
|
|
|
|
|
|
def check_global_compatibility(request: HttpRequest) -> HttpResponse:
|
|
if request.META.get("HTTP_USER_AGENT") is None:
|
|
return json_error(_("User-Agent header missing from request"))
|
|
|
|
# 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(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(legacy_compatibility_error_message)
|
|
return json_success()
|