summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
Diffstat (limited to 'synapse')
-rw-r--r--synapse/__init__.py2
-rw-r--r--synapse/api/auth.py5
-rw-r--r--synapse/handlers/presence.py18
-rw-r--r--synapse/handlers/room.py2
-rw-r--r--synapse/notifier.py21
-rw-r--r--synapse/rest/profile.py21
-rw-r--r--synapse/storage/__init__.py3
-rw-r--r--synapse/storage/room.py2
8 files changed, 66 insertions, 8 deletions
diff --git a/synapse/__init__.py b/synapse/__init__.py
index 47fc1b2ea4..04200060bf 100644
--- a/synapse/__init__.py
+++ b/synapse/__init__.py
@@ -16,4 +16,4 @@
 """ This is a reference implementation of a synapse home server.
 """
 
-__version__ = "0.0.1"
+__version__ = "0.1.2"
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index e9e3279b9a..54ecbe5b3a 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -169,6 +169,11 @@ class Auth(object):
                 )
                 _, kick_level = yield self.store.get_ops_levels(event.room_id)
 
+                if kick_level:
+                    kick_level = int(kick_level)
+                else:
+                    kick_level = 5
+
                 if user_level < kick_level:
                     raise AuthError(
                         403, "You cannot kick user %s." % target_user_id
diff --git a/synapse/handlers/presence.py b/synapse/handlers/presence.py
index 7372a10f9b..9bfceda88a 100644
--- a/synapse/handlers/presence.py
+++ b/synapse/handlers/presence.py
@@ -650,15 +650,25 @@ class PresenceHandler(BaseHandler):
             room_ids = yield rm_handler.get_rooms_for_user(user)
 
             if not observers and not room_ids:
-                break
+                continue
 
             state = dict(push)
             del state["user_id"]
 
-            # Legacy handling
-            if "presence" not in state:
+            if "presence" in state:
+                # all is OK
+                pass
+            elif "state" in state:
+                # Legacy handling
                 state["presence"] = state["state"]
-            del state["state"]
+            else:
+                logger.warning("Received a presence 'push' EDU from %s without"
+                    + " either a 'presence' or 'state' key", origin
+                )
+                continue
+
+            if "state" in state:
+                del state["state"]
 
             if "last_active_ago" in state:
                 state["last_active"] = int(
diff --git a/synapse/handlers/room.py b/synapse/handlers/room.py
index b0c94d35af..34a19bc64e 100644
--- a/synapse/handlers/room.py
+++ b/synapse/handlers/room.py
@@ -134,6 +134,7 @@ class RoomCreationHandler(BaseRoomHandler):
                 etype=RoomNameEvent.TYPE,
                 room_id=room_id,
                 user_id=user_id,
+                required_power_level=5,
                 content={"name": name},
             )
 
@@ -145,6 +146,7 @@ class RoomCreationHandler(BaseRoomHandler):
                 etype=RoomTopicEvent.TYPE,
                 room_id=room_id,
                 user_id=user_id,
+                required_power_level=5,
                 content={"topic": topic},
             )
 
diff --git a/synapse/notifier.py b/synapse/notifier.py
index cb544e9886..3260aa744f 100644
--- a/synapse/notifier.py
+++ b/synapse/notifier.py
@@ -106,7 +106,9 @@ class Notifier(object):
 
         # TODO (erikj): Can we make this more efficient by hitting the
         # db once?
-        for listener in listeners:
+
+        @defer.inlineCallbacks
+        def notify(listener):
             events, end_key = yield room_source.get_new_events_for_user(
                 listener.user,
                 listener.from_token.room_key,
@@ -122,6 +124,13 @@ class Notifier(object):
                     self, events, listener.from_token, end_token
                 )
 
+        def eb(failure):
+            logger.exception("Failed to notify listener", failure)
+
+        yield defer.DeferredList(
+            [notify(l).addErrback(eb) for l in listeners]
+        )
+
     @defer.inlineCallbacks
     @log_function
     def on_new_user_event(self, users=[], rooms=[]):
@@ -140,7 +149,8 @@ class Notifier(object):
         for room in rooms:
             listeners |= self.rooms_to_listeners.get(room, set()).copy()
 
-        for listener in listeners:
+        @defer.inlineCallbacks
+        def notify(listener):
             events, end_key = yield presence_source.get_new_events_for_user(
                 listener.user,
                 listener.from_token.presence_key,
@@ -156,6 +166,13 @@ class Notifier(object):
                     self, events, listener.from_token, end_token
                 )
 
+        def eb(failure):
+            logger.exception("Failed to notify listener", failure)
+
+        yield defer.DeferredList(
+            [notify(l).addErrback(eb) for l in listeners]
+        )
+
     def get_events_for(self, user, rooms, pagination_config, timeout):
         """ For the given user and rooms, return any new events for them. If
         there are no new events wait for up to `timeout` milliseconds for any
diff --git a/synapse/rest/profile.py b/synapse/rest/profile.py
index 2f010c0182..06076667c7 100644
--- a/synapse/rest/profile.py
+++ b/synapse/rest/profile.py
@@ -87,6 +87,27 @@ class ProfileAvatarURLRestServlet(RestServlet):
         return (200, {})
 
 
+class ProfileRestServlet(RestServlet):
+    PATTERN = client_path_pattern("/profile/(?P<user_id>[^/]*)")
+
+    @defer.inlineCallbacks
+    def on_GET(self, request, user_id):
+        user = self.hs.parse_userid(user_id)
+
+        displayname = yield self.handlers.profile_handler.get_displayname(
+            user,
+        )
+        avatar_url = yield self.handlers.profile_handler.get_avatar_url(
+            user,
+        )
+
+        defer.returnValue((200, {
+                                    "displayname": displayname,
+                                    "avatar_url": avatar_url
+                                }))
+
+
 def register_servlets(hs, http_server):
     ProfileDisplaynameRestServlet(hs).register(http_server)
     ProfileAvatarURLRestServlet(hs).register(http_server)
+    ProfileRestServlet(hs).register(http_server)
diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py
index 7a441391f0..aadaab06e7 100644
--- a/synapse/storage/__init__.py
+++ b/synapse/storage/__init__.py
@@ -23,6 +23,7 @@ from synapse.api.events.room import (
     RoomPowerLevelsEvent,
     RoomAddStateLevelEvent,
     RoomSendEventLevelEvent,
+    RoomOpsPowerLevelsEvent,
 )
 
 from synapse.util.logutils import log_function
@@ -140,6 +141,8 @@ class DataStore(RoomMemberStore, RoomStore,
             self._store_add_state_level(txn, event)
         elif event.type == RoomSendEventLevelEvent.TYPE:
             self._store_send_event_level(txn, event)
+        elif event.type == RoomOpsPowerLevelsEvent.TYPE:
+            self._store_ops_level(txn, event)
 
         vals = {
             "topological_ordering": event.depth,
diff --git a/synapse/storage/room.py b/synapse/storage/room.py
index 3ca07f4350..01ae190316 100644
--- a/synapse/storage/room.py
+++ b/synapse/storage/room.py
@@ -328,7 +328,7 @@ class RoomStore(SQLBaseStore):
 
         self._simple_insert_txn(
             txn,
-            "room_send_event_levels",
+            "room_ops_levels",
             content,
         )