summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
Diffstat (limited to 'synapse')
-rw-r--r--synapse/api/auth.py5
-rw-r--r--synapse/rest/client/v2_alpha/register.py11
-rw-r--r--synapse/storage/events.py34
3 files changed, 26 insertions, 24 deletions
diff --git a/synapse/api/auth.py b/synapse/api/auth.py
index 3d1ce4e09e..be67ab4f4d 100644
--- a/synapse/api/auth.py
+++ b/synapse/api/auth.py
@@ -121,6 +121,11 @@ class Auth(object):
 
             # FIXME: Temp hack
             if event.type == EventTypes.Aliases:
+                if not event.is_state():
+                    raise AuthError(
+                        403,
+                        "Alias event must be a state event",
+                    )
                 if not event.state_key:
                     raise AuthError(
                         403,
diff --git a/synapse/rest/client/v2_alpha/register.py b/synapse/rest/client/v2_alpha/register.py
index 7c6d2942dc..e8d34b06b0 100644
--- a/synapse/rest/client/v2_alpha/register.py
+++ b/synapse/rest/client/v2_alpha/register.py
@@ -132,11 +132,12 @@ class RegisterRestServlet(RestServlet):
             # Set the desired user according to the AS API (which uses the
             # 'user' key not 'username'). Since this is a new addition, we'll
             # fallback to 'username' if they gave one.
-            if isinstance(body.get("user"), basestring):
-                desired_username = body["user"]
-            result = yield self._do_appservice_registration(
-                desired_username, request.args["access_token"][0]
-            )
+            desired_username = body.get("user", desired_username)
+
+            if isinstance(desired_username, basestring):
+                result = yield self._do_appservice_registration(
+                    desired_username, request.args["access_token"][0]
+                )
             defer.returnValue((200, result))  # we throw for non 200 responses
             return
 
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 59f8061333..9d74fd159d 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -1343,7 +1343,7 @@ class EventsStore(SQLBaseStore):
         # We calculate the new entries for the backward extremeties by finding
         # all events that point to events that are to be purged
         txn.execute(
-            "SELECT e.event_id FROM events as e"
+            "SELECT DISTINCT e.event_id FROM events as e"
             " INNER JOIN event_edges as ed ON e.event_id = ed.prev_event_id"
             " INNER JOIN events as e2 ON e2.event_id = ed.event_id"
             " WHERE e.room_id = ? AND e.topological_ordering < ?"
@@ -1352,6 +1352,20 @@ class EventsStore(SQLBaseStore):
         )
         new_backwards_extrems = txn.fetchall()
 
+        txn.execute(
+            "DELETE FROM event_backward_extremities WHERE room_id = ?",
+            (room_id,)
+        )
+
+        # Update backward extremeties
+        txn.executemany(
+            "INSERT INTO event_backward_extremities (room_id, event_id)"
+            " VALUES (?, ?)",
+            [
+                (room_id, event_id) for event_id, in new_backwards_extrems
+            ]
+        )
+
         # Get all state groups that are only referenced by events that are
         # to be deleted.
         txn.execute(
@@ -1404,30 +1418,12 @@ class EventsStore(SQLBaseStore):
             "event_search",
             "event_signatures",
             "rejections",
-            "event_backward_extremities",
         ):
             txn.executemany(
                 "DELETE FROM %s WHERE event_id = ?" % (table,),
                 to_delete
             )
 
-        txn.execute(
-            "SELECT event_id FROM event_backward_extremities WHERE room_id = ?",
-            (room_id,)
-        )
-
-        cur_back_event_ids = [event_id for event_id, in txn.fetchall()]
-
-        # Update backward extremeties
-        txn.executemany(
-            "INSERT INTO event_backward_extremities (room_id, event_id)"
-            " VALUES (?, ?)",
-            [
-                (room_id, event_id) for event_id, in new_backwards_extrems
-                if event_id not in cur_back_event_ids
-            ]
-        )
-
         txn.executemany(
             "DELETE FROM events WHERE event_id = ?",
             to_delete