summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2018-05-03 01:29:04 +0100
committerMatthew Hodgson <matthew@matrix.org>2018-05-03 01:29:12 +0100
commitf93cb7410d7c8d6c708f7edf8c8fb545fa55406d (patch)
treea4d76078e6a03186ce9e37263cbde85f9f567a47
parentMerge branch 'master' into dinsic (diff)
downloadsynapse-f93cb7410d7c8d6c708f7edf8c8fb545fa55406d.tar.xz
options to disable setting profile info
-rw-r--r--synapse/config/registration.py12
-rw-r--r--synapse/handlers/profile.py10
2 files changed, 22 insertions, 0 deletions
diff --git a/synapse/config/registration.py b/synapse/config/registration.py
index 34326718ad..cbc1d3d00e 100644
--- a/synapse/config/registration.py
+++ b/synapse/config/registration.py
@@ -49,6 +49,9 @@ class RegistrationConfig(Config):
 
         self.auto_join_rooms = config.get("auto_join_rooms", [])
 
+        self.disable_set_displayname = config.get("disable_set_displayname", False)
+        self.disable_set_avatar_url = config.get("disable_set_avatar_url", False)
+
         self.replicate_user_profiles_to = config.get("replicate_user_profiles_to", [])
         if not isinstance(self.replicate_user_profiles_to, list):
             self.replicate_user_profiles_to = [self.replicate_user_profiles_to, ]
@@ -118,10 +121,19 @@ class RegistrationConfig(Config):
         # cross-homeserver user directories.
         # replicate_user_profiles_to: example.com
 
+        # If enabled, don't let users set their own display names/avatars
+        # other than for the very first time (unless they are a server admin).
+        # Useful when provisioning users based on the contents of a 3rd party
+        # directory and to avoid ambiguities.
+        #
+        # disable_set_displayname: True
+        # disable_set_avatar_url: True
+
         # Users who register on this homeserver will automatically be joined
         # to these rooms
         #auto_join_rooms:
         #    - "#example:example.com"
+
         """ % locals()
 
     def add_arguments(self, parser):
diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py
index 7c5591056d..1a79004d57 100644
--- a/synapse/handlers/profile.py
+++ b/synapse/handlers/profile.py
@@ -215,6 +215,11 @@ class ProfileHandler(BaseHandler):
         if not by_admin and target_user != requester.user:
             raise AuthError(400, "Cannot set another user's displayname")
 
+        if not by_admin and self.hs.config.disable_set_displayname:
+            profile = yield self.store.get_profileinfo(target_user.localpart)
+            if profile.display_name:
+                raise SynapseError(400, "Changing displayname is disabled on this server")
+
         if new_displayname == '':
             new_displayname = None
 
@@ -277,6 +282,11 @@ class ProfileHandler(BaseHandler):
         if not by_admin and target_user != requester.user:
             raise AuthError(400, "Cannot set another user's avatar_url")
 
+        if not by_admin and self.hs.config.disable_set_avatar_url:
+            profile = yield self.store.get_profileinfo(target_user.localpart)
+            if profile.avatar_url:
+                raise SynapseError(400, "Changing avatar url is disabled on this server")
+
         if len(self.hs.config.replicate_user_profiles_to) > 0:
             cur_batchnum = yield self.store.get_latest_profile_replication_batch_number()
             new_batchnum = 0 if cur_batchnum is None else cur_batchnum + 1