From b3e346f40c00268f4b9cf7e9d2b26b4864d17412 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 4 May 2018 01:56:01 +0100 Subject: [PATCH] don't pass a requester if we don't have one to set_displayname --- synapse/handlers/profile.py | 9 +++++---- synapse/handlers/register.py | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/synapse/handlers/profile.py b/synapse/handlers/profile.py index 94bd5347a..a9c76f323 100644 --- a/synapse/handlers/profile.py +++ b/synapse/handlers/profile.py @@ -207,12 +207,12 @@ class ProfileHandler(BaseHandler): @defer.inlineCallbacks def set_displayname(self, target_user, requester, new_displayname, by_admin=False): - """target_user is the user whose displayname is to be changed; - requester is the user attempting to make this change.""" + """target_user is the UserID whose displayname is to be changed; + requester is the authenticated user attempting to make this change.""" if not self.hs.is_mine(target_user): raise SynapseError(400, "User is not hosted on this Home Server") - if not by_admin and target_user != requester.user: + if not by_admin and requester 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: @@ -239,7 +239,8 @@ class ProfileHandler(BaseHandler): target_user.to_string(), profile ) - yield self._update_join_states(requester, target_user) + if requester: + yield self._update_join_states(requester, target_user) # start a profile replication push run_in_background(self._replicate_profiles) diff --git a/synapse/handlers/register.py b/synapse/handlers/register.py index 14031cea4..e308fcbb4 100644 --- a/synapse/handlers/register.py +++ b/synapse/handlers/register.py @@ -178,7 +178,7 @@ class RegistrationHandler(BaseHandler): if display_name: yield self.profile_handler.set_displayname( - user, user, display_name, by_admin=True, + user, None, display_name, by_admin=True, ) if self.hs.config.user_directory_search_all_users: @@ -208,7 +208,7 @@ class RegistrationHandler(BaseHandler): ) yield self.profile_handler.set_displayname( - user, user, user.localpart, by_admin=True, + user, None, user.localpart, by_admin=True, ) except SynapseError: @@ -257,7 +257,7 @@ class RegistrationHandler(BaseHandler): ) yield self.profile_handler.set_displayname( - user, user, user.localpart, by_admin=True, + user, None, user.localpart, by_admin=True, ) defer.returnValue(user_id) @@ -308,7 +308,7 @@ class RegistrationHandler(BaseHandler): ) yield self.profile_handler.set_displayname( - user, user, user.localpart, by_admin=True, + user, None, user.localpart, by_admin=True, ) except Exception as e: yield self.store.add_access_token_to_user(user_id, token) @@ -466,7 +466,7 @@ class RegistrationHandler(BaseHandler): ) if displayname is not None: yield self.profile_handler.set_displayname( - user, user, displayname, by_admin=True, + user, None, displayname, by_admin=True, ) else: yield self._auth_handler.delete_access_tokens_for_user(user_id)