summary refs log tree commit diff
path: root/synapse/handlers/directory.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-02-09 15:01:28 +0000
committerKegan Dougal <kegan@matrix.org>2015-02-09 15:01:28 +0000
commitf7cac2f7b699fb3bb58c02fa1828aeec6c319f01 (patch)
tree34d975546d13d888fe42832f21a6db16a9c19948 /synapse/handlers/directory.py
parentRemove unused imports. (diff)
downloadsynapse-f7cac2f7b699fb3bb58c02fa1828aeec6c319f01.tar.xz
Fix bugs so lazy room joining works as intended.
Diffstat (limited to 'synapse/handlers/directory.py')
-rw-r--r--synapse/handlers/directory.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index 22c6391a15..87bc12c983 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -64,8 +64,11 @@ class DirectoryHandler(BaseHandler):
         # association creation for human users
         # TODO(erikj): Do user auth.
 
-        is_claimed = yield self.is_alias_exclusive_to_appservices(room_alias)
-        if is_claimed:
+        can_create = yield self.can_modify_alias(
+            room_alias,
+            user_id=user_id
+        )
+        if not can_create:
             raise SynapseError(
                 400, "This alias is reserved by an application service.",
                 errcode=Codes.EXCLUSIVE
@@ -91,8 +94,11 @@ class DirectoryHandler(BaseHandler):
 
         # TODO Check if server admin
 
-        is_claimed = yield self.is_alias_exclusive_to_appservices(room_alias)
-        if is_claimed:
+        can_delete = yield self.can_modify_alias(
+            room_alias,
+            user_id=user_id
+        )
+        if not can_delete:
             raise SynapseError(
                 400, "This alias is reserved by an application service.",
                 errcode=Codes.EXCLUSIVE
@@ -228,9 +234,14 @@ class DirectoryHandler(BaseHandler):
         defer.returnValue(result)
 
     @defer.inlineCallbacks
-    def is_alias_exclusive_to_appservices(self, alias):
+    def can_modify_alias(self, alias, user_id=None):
         services = yield self.store.get_app_services()
         interested_services = [
             s for s in services if s.is_interested_in_alias(alias.to_string())
         ]
-        defer.returnValue(len(interested_services) > 0)
+        for service in interested_services:
+            if user_id == service.sender:
+                # this user IS the app service
+                defer.returnValue(True)
+                return
+        defer.returnValue(len(interested_services) == 0)