mobile: Add an endpoint for checking compatibility.

This commit is contained in:
Tim Abbott 2017-01-29 22:21:13 -08:00
parent cb1d61cae0
commit fa02dfdff4
4 changed files with 31 additions and 0 deletions

View File

@ -368,6 +368,7 @@ def build_custom_checkers(by_lang):
('zerver/middleware.py',
'return json_error(exception.to_json_error_msg(), status=status_code)'),
('zerver/tornado/views.py', 'return json_error(result["message"])'),
('zerver/views/compatibility.py', 'return json_error("Client is too old")'),
('zerver/views/invite.py',
'return json_error(data=error_data, msg=ret_error)'),
('zerver/views/streams.py', 'return json_error(property_conversion)'),

View File

@ -0,0 +1,12 @@
from __future__ import absolute_import
from __future__ import print_function
from zerver.lib.test_classes import ZulipTestCase
class CompatibilityTest(ZulipTestCase):
def test_compatibility(self):
# type: () -> None
result = self.client_get("/compatibility", HTTP_USER_AGENT='ZulipMobile/5.0')
self.assert_json_success(result)
result = self.client_get("/compatibility", HTTP_USER_AGENT='ZulipInvalid/5.0')
self.assert_json_error(result, "Client is too old")

View File

@ -0,0 +1,14 @@
from __future__ import absolute_import
from django.http import HttpResponse, HttpRequest
from typing import Any, List, Dict, Optional, Text
from zerver.lib.response import json_error, json_success
from zerver.lib.user_agent import parse_user_agent
def check_compatibility(request):
# type: (HttpRequest) -> HttpResponse
user_agent = parse_user_agent(request.META["HTTP_USER_AGENT"])
if user_agent['name'] == "ZulipInvalid":
return json_error("Client is too old")
return json_success()

View File

@ -18,6 +18,7 @@ from django.contrib.auth.views import (login, password_reset,
import zerver.tornado.views
import zerver.views
import zerver.views.auth
import zerver.views.compatibility
import zerver.views.home
import zerver.views.registration
import zerver.views.zephyr
@ -351,6 +352,9 @@ urls += [
# backends the server allows, to display the proper UI and check for server existence
url(r'^api/v1/get_auth_backends', zerver.views.auth.api_get_auth_backends, name='zerver.views.auth.api_get_auth_backends'),
# used by mobile apps to check if they are compatible with the server
url(r'^compatibility$', zerver.views.compatibility.check_compatibility),
# This json format view used by the mobile apps accepts a username
# password/pair and returns an API key.
url(r'^api/v1/fetch_api_key$', zerver.views.auth.api_fetch_api_key, name='zerver.views.auth.api_fetch_api_key'),