summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
authorKegsay <kegsay@gmail.com>2015-03-02 14:56:32 +0000
committerKegsay <kegsay@gmail.com>2015-03-02 14:56:32 +0000
commit8ad024ea80ab8f9747472df3e96154b51c04ae13 (patch)
treecfc962d742805c866885aae7b4ec41dd4400e94e /synapse/handlers
parentMerge pull request #88 from matrix-org/batched_get_pdu (diff)
parentWording tweaks (diff)
downloadsynapse-8ad024ea80ab8f9747472df3e96154b51c04ae13.tar.xz
Merge pull request #93 from matrix-org/application-services-exclusive
Application services exclusive flag support
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/directory.py14
-rw-r--r--synapse/handlers/register.py11
2 files changed, 18 insertions, 7 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)
diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py
index 516a936cee..cda4a8502a 100644
--- a/synapse/handlers/register.py
+++ b/synapse/handlers/register.py
@@ -201,11 +201,12 @@ class RegistrationHandler(BaseHandler):
         interested_services = [
             s for s in services if s.is_interested_in_user(user_id)
         ]
-        if len(interested_services) > 0:
-            raise SynapseError(
-                400, "This user ID is reserved by an application service.",
-                errcode=Codes.EXCLUSIVE
-            )
+        for service in interested_services:
+            if service.is_exclusive_user(user_id):
+                raise SynapseError(
+                    400, "This user ID is reserved by an application service.",
+                    errcode=Codes.EXCLUSIVE
+                )
 
     def _generate_token(self, user_id):
         # urlsafe variant uses _ and - so use . as the separator and replace