summary refs log tree commit diff
path: root/synapse/handlers/directory.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-02-27 13:51:41 +0000
committerKegan Dougal <kegan@matrix.org>2015-02-27 13:51:41 +0000
commit58ff0660642e6ef8f9fe5672fb50e5d75a569479 (patch)
tree4c1ec2625e6a96ef8a3ebf1d0d6a135b8606ad70 /synapse/handlers/directory.py
parentAdd more unit tests for exclusive namespaces. (diff)
downloadsynapse-58ff0660642e6ef8f9fe5672fb50e5d75a569479.tar.xz
Implement exclusive namespace checks.
Diffstat (limited to 'synapse/handlers/directory.py')
-rw-r--r--synapse/handlers/directory.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/synapse/handlers/directory.py b/synapse/handlers/directory.py
index 11d20a5d2d..f76febee8f 100644
--- a/synapse/handlers/directory.py
+++ b/synapse/handlers/directory.py
@@ -232,13 +232,23 @@ class DirectoryHandler(BaseHandler):
 
     @defer.inlineCallbacks
     def can_modify_alias(self, alias, user_id=None):
+        # Any application service "interested" in an alias they are regexing on
+        # can modify the alias.
+        # Users can only modify the alias if ALL the interested services have
+        # non-exclusive locks on the alias (or there are no interested services)
         services = yield self.store.get_app_services()
         interested_services = [
             s for s in services if s.is_interested_in_alias(alias.to_string())
         ]
+
         for service in interested_services:
             if user_id == service.sender:
-                # this user IS the app service
+                # this user IS the app service so they can do whatever they like
                 defer.returnValue(True)
                 return
-        defer.returnValue(len(interested_services) == 0)
+            elif service.is_exclusive_alias(alias.to_string()):
+                # another service has an exclusive lock on this alias.
+                defer.returnValue(False)
+                return
+        # either no interested services, or no service with an exclusive lock
+        defer.returnValue(True)