mirror of https://github.com/zulip/zulip.git
compatibility: Add a compatibility check to api_get_server_settings.
This should make it convenient for the mobile app to present errors of the form "Your Zulip app is not new enough for this Zulip server".
This commit is contained in:
parent
8711fe7bae
commit
be9b6a6dee
|
@ -1705,6 +1705,11 @@ paths:
|
|||
type: boolean
|
||||
description: Whether mobile/push notifications are
|
||||
enabled.
|
||||
is_incompatible:
|
||||
type: boolean
|
||||
description: Whether the Zulip client that has sent a
|
||||
request to this endpoint is deemed incompatible with
|
||||
the server.
|
||||
email_auth_enabled:
|
||||
type: boolean
|
||||
description: Setting for allowing users authenticate with
|
||||
|
|
|
@ -1528,6 +1528,7 @@ class FetchAuthBackends(ZulipTestCase):
|
|||
('password', check_bool),
|
||||
])),
|
||||
('email_auth_enabled', check_bool),
|
||||
('is_incompatible', check_bool),
|
||||
('require_email_format_usernames', check_bool),
|
||||
('realm_uri', check_string),
|
||||
('zulip_version', check_string),
|
||||
|
@ -1537,15 +1538,18 @@ class FetchAuthBackends(ZulipTestCase):
|
|||
] + extra_fields)
|
||||
self.assert_on_error(checker("data", result.json()))
|
||||
|
||||
result = self.client_get("/api/v1/server_settings", subdomain="")
|
||||
result = self.client_get("/api/v1/server_settings", subdomain="", HTTP_USER_AGENT="")
|
||||
check_result(result)
|
||||
|
||||
result = self.client_get("/api/v1/server_settings", subdomain="", HTTP_USER_AGENT="ZulipInvalid")
|
||||
self.assertTrue(result.json()["is_incompatible"])
|
||||
|
||||
with self.settings(ROOT_DOMAIN_LANDING_PAGE=False):
|
||||
result = self.client_get("/api/v1/server_settings", subdomain="", HTTP_USER_AGENT="")
|
||||
check_result(result)
|
||||
|
||||
with self.settings(ROOT_DOMAIN_LANDING_PAGE=False):
|
||||
result = self.client_get("/api/v1/server_settings", subdomain="")
|
||||
check_result(result)
|
||||
|
||||
with self.settings(ROOT_DOMAIN_LANDING_PAGE=False):
|
||||
result = self.client_get("/api/v1/server_settings", subdomain="zulip")
|
||||
result = self.client_get("/api/v1/server_settings", subdomain="zulip", HTTP_USER_AGENT="")
|
||||
check_result(result, [
|
||||
('realm_name', check_string),
|
||||
('realm_description', check_string),
|
||||
|
|
|
@ -31,6 +31,7 @@ from zerver.lib.push_notifications import push_notifications_enabled
|
|||
from zerver.lib.request import REQ, has_request_variables, JsonableError
|
||||
from zerver.lib.response import json_success, json_error
|
||||
from zerver.lib.subdomains import get_subdomain, is_subdomain_root_or_alias
|
||||
from zerver.lib.user_agent import parse_user_agent
|
||||
from zerver.lib.users import get_api_key
|
||||
from zerver.lib.validator import validate_login_email
|
||||
from zerver.models import PreregistrationUser, UserProfile, remote_user_to_email, Realm, \
|
||||
|
@ -843,6 +844,10 @@ def api_get_auth_backends(request: HttpRequest) -> HttpResponse:
|
|||
auth_backends['zulip_version'] = ZULIP_VERSION
|
||||
return json_success(auth_backends)
|
||||
|
||||
def check_server_incompatibility(request: HttpRequest) -> bool:
|
||||
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
|
||||
return user_agent['name'] == "ZulipInvalid"
|
||||
|
||||
@require_GET
|
||||
@csrf_exempt
|
||||
def api_get_server_settings(request: HttpRequest) -> HttpResponse:
|
||||
|
@ -850,6 +855,7 @@ def api_get_server_settings(request: HttpRequest) -> HttpResponse:
|
|||
authentication_methods=get_auth_backends_data(request),
|
||||
zulip_version=ZULIP_VERSION,
|
||||
push_notifications_enabled=push_notifications_enabled(),
|
||||
is_incompatible=check_server_incompatibility(request),
|
||||
)
|
||||
context = zulip_default_context(request)
|
||||
# IMPORTANT NOTE:
|
||||
|
|
|
@ -590,7 +590,8 @@ urls += [
|
|||
urls += [
|
||||
# This json format view used by the mobile apps lists which
|
||||
# authentication backends the server allows as well as details
|
||||
# like the requested subdomains'd realm icon (if known).
|
||||
# like the requested subdomains'd realm icon (if known) and
|
||||
# server-specific compatibility.
|
||||
url(r'^api/v1/server_settings', zerver.views.auth.api_get_server_settings),
|
||||
# This is a deprecated old version of api/v1/server_settings that only returns auth backends.
|
||||
url(r'^api/v1/get_auth_backends', zerver.views.auth.api_get_auth_backends,
|
||||
|
|
Loading…
Reference in New Issue