From c75add6ec87cb548b5cc74b7e6e0c56d78d5eae9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 11:52:56 +0100 Subject: Added a urls module for keeping client and federation prefixes. --- synapse/api/urls.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 synapse/api/urls.py (limited to 'synapse/api') diff --git a/synapse/api/urls.py b/synapse/api/urls.py new file mode 100644 index 0000000000..7a6fff7d18 --- /dev/null +++ b/synapse/api/urls.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2014 matrix.org +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Contains the URL paths to prefix various aspects of the server with. """ + +CLIENT_PREFIX = "/matrix/client/api/v1" +FEDERATION_PREFIX = "/matrix/federation/v1" \ No newline at end of file -- cgit 1.4.1 From d253a3553967948e277929549a4ae6367584342f Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 11:54:37 +0100 Subject: Added web client prefix --- synapse/api/urls.py | 3 ++- synapse/app/homeserver.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'synapse/api') diff --git a/synapse/api/urls.py b/synapse/api/urls.py index 7a6fff7d18..04970adb71 100644 --- a/synapse/api/urls.py +++ b/synapse/api/urls.py @@ -16,4 +16,5 @@ """Contains the URL paths to prefix various aspects of the server with. """ CLIENT_PREFIX = "/matrix/client/api/v1" -FEDERATION_PREFIX = "/matrix/federation/v1" \ No newline at end of file +FEDERATION_PREFIX = "/matrix/federation/v1" +WEB_CLIENT_PREFIX = "/matrix/client" \ No newline at end of file diff --git a/synapse/app/homeserver.py b/synapse/app/homeserver.py index 7c356e7855..fc12e0dba5 100644 --- a/synapse/app/homeserver.py +++ b/synapse/app/homeserver.py @@ -26,7 +26,7 @@ from twisted.web.static import File from twisted.web.server import Site from synapse.http.server import JsonResource, RootRedirect from synapse.http.client import TwistedHttpClient -from synapse.api.urls import CLIENT_PREFIX, FEDERATION_PREFIX +from synapse.api.urls import CLIENT_PREFIX, FEDERATION_PREFIX, WEB_CLIENT_PREFIX from daemonize import Daemonize @@ -104,11 +104,11 @@ class SynapseHomeServer(HomeServer): ] if web_client: logger.info("Adding the web client.") - desired_tree.append(("/matrix/client", # TODO constant please + desired_tree.append((WEB_CLIENT_PREFIX, self.get_resource_for_web_client())) if web_client and redirect_root_to_web_client: - self.root_resource = RootRedirect("/matrix/client") + self.root_resource = RootRedirect(WEB_CLIENT_PREFIX) else: self.root_resource = Resource() -- cgit 1.4.1 From 2a793a6c422e24a064b034f7dcdab816a667af73 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 11:57:25 +0100 Subject: Default error code BAD_PAGINATION for EventStreamErrors --- synapse/api/errors.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'synapse/api') diff --git a/synapse/api/errors.py b/synapse/api/errors.py index 8b9766fab7..b5970c959b 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -74,7 +74,10 @@ class AuthError(SynapseError): class EventStreamError(SynapseError): """An error raised when there a problem with the event stream.""" - pass + def __init__(self, *args, **kwargs): + if "errcode" not in kwargs: + kwargs["errcode"] = Codes.BAD_PAGINATION + super(EventStreamError, self).__init__(*args, **kwargs) class LoginError(SynapseError): -- cgit 1.4.1 From 61933f8e5278fda03e34eb25b729dd6a3987b6ab Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 14 Aug 2014 13:47:39 +0100 Subject: Added M_UNKNOWN_TOKEN error code and send it when there is an unrecognised access_token --- docs/client-server/specification.rst | 5 ++++- synapse/api/auth.py | 5 +++-- synapse/api/errors.py | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'synapse/api') diff --git a/docs/client-server/specification.rst b/docs/client-server/specification.rst index 7df2bb14c5..97c8587a6d 100644 --- a/docs/client-server/specification.rst +++ b/docs/client-server/specification.rst @@ -262,7 +262,10 @@ the error, but the keys 'error' and 'errcode' will always be present. Some standard error codes are below: M_FORBIDDEN: -Forbidden access, e.g. bad access token, failed login. +Forbidden access, e.g. joining a room without permission, failed login. + +M_UNKNOWN_TOKEN: +The access token specified was not recognised. M_BAD_JSON: Request contained valid JSON, but it was malformed in some way, e.g. missing diff --git a/synapse/api/auth.py b/synapse/api/auth.py index 8d2ba242e1..31852b29a5 100644 --- a/synapse/api/auth.py +++ b/synapse/api/auth.py @@ -18,7 +18,7 @@ from twisted.internet import defer from synapse.api.constants import Membership -from synapse.api.errors import AuthError, StoreError +from synapse.api.errors import AuthError, StoreError, Codes from synapse.api.events.room import (RoomTopicEvent, RoomMemberEvent, MessageEvent, FeedbackEvent) @@ -163,4 +163,5 @@ class Auth(object): user_id = yield self.store.get_user_by_token(token=token) defer.returnValue(self.hs.parse_userid(user_id)) except StoreError: - raise AuthError(403, "Unrecognised access token.") + raise AuthError(403, "Unrecognised access token.", + errcode=Codes.UNKNOWN_TOKEN) diff --git a/synapse/api/errors.py b/synapse/api/errors.py index b5970c959b..21ededc5ae 100644 --- a/synapse/api/errors.py +++ b/synapse/api/errors.py @@ -27,6 +27,7 @@ class Codes(object): BAD_PAGINATION = "M_BAD_PAGINATION" UNKNOWN = "M_UNKNOWN" NOT_FOUND = "M_NOT_FOUND" + UNKNOWN_TOKEN = "M_UNKNOWN_TOKEN" class CodeMessageException(Exception): -- cgit 1.4.1 From 33d62c2c6674cf19f5261817bff81cd5209408bd Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Fri, 15 Aug 2014 11:40:58 +0100 Subject: Remember to reflect membership LEAVE events to the leaving member so they know it happened --- synapse/api/notifier.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'synapse/api') diff --git a/synapse/api/notifier.py b/synapse/api/notifier.py index 105a11401b..65b5a4ebb3 100644 --- a/synapse/api/notifier.py +++ b/synapse/api/notifier.py @@ -56,6 +56,10 @@ class Notifier(object): if (event.type == RoomMemberEvent.TYPE and event.content["membership"] == Membership.INVITE): member_list.append(event.target_user_id) + # similarly, LEAVEs must be sent to the person leaving + if (event.type == RoomMemberEvent.TYPE and + event.content["membership"] == Membership.LEAVE): + member_list.append(event.target_user_id) for user_id in member_list: if user_id in self.stored_event_listeners: -- cgit 1.4.1