make profile shadowing work
This commit is contained in:
@@ -189,6 +189,7 @@ class Auth(object):
|
||||
# Can optionally look elsewhere in the request (e.g. headers)
|
||||
try:
|
||||
user_id, app_service = yield self._get_appservice_user_id(request)
|
||||
|
||||
if user_id:
|
||||
request.authenticated_entity = user_id
|
||||
defer.returnValue(
|
||||
@@ -244,6 +245,7 @@ class Auth(object):
|
||||
request, self.TOKEN_NOT_FOUND_HTTP_STATUS
|
||||
)
|
||||
)
|
||||
|
||||
if app_service is None:
|
||||
return(None, None)
|
||||
|
||||
@@ -514,24 +516,9 @@ class Auth(object):
|
||||
defer.returnValue(user_info)
|
||||
|
||||
def get_appservice_by_req(self, request):
|
||||
try:
|
||||
token = self.get_access_token_from_request(
|
||||
request, self.TOKEN_NOT_FOUND_HTTP_STATUS
|
||||
)
|
||||
service = self.store.get_app_service_by_token(token)
|
||||
if not service:
|
||||
logger.warn("Unrecognised appservice access token.")
|
||||
raise AuthError(
|
||||
self.TOKEN_NOT_FOUND_HTTP_STATUS,
|
||||
"Unrecognised access token.",
|
||||
errcode=Codes.UNKNOWN_TOKEN
|
||||
)
|
||||
request.authenticated_entity = service.sender
|
||||
return defer.succeed(service)
|
||||
except KeyError:
|
||||
raise AuthError(
|
||||
self.TOKEN_NOT_FOUND_HTTP_STATUS, "Missing access token."
|
||||
)
|
||||
(user_id, appservice) = self._get_appservice_user_id(request)
|
||||
request.authenticated_entity = service.sender
|
||||
return appservice
|
||||
|
||||
def is_server_admin(self, user):
|
||||
""" Check if the given user is a local server admin.
|
||||
|
||||
@@ -148,6 +148,7 @@ class RegistrationConfig(Config):
|
||||
# via a given AS token.
|
||||
# shadow_server:
|
||||
# hs_url: https://shadow.example.com
|
||||
# hs: shadow.example.com
|
||||
# as_token: 12u394refgbdhivsia
|
||||
|
||||
# If enabled, don't let users set their own display names/avatars
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
# limitations under the License.
|
||||
|
||||
""" This module contains REST servlets to do with profile: /profile/<paths> """
|
||||
import logging
|
||||
|
||||
from twisted.internet import defer
|
||||
|
||||
from synapse.http.servlet import parse_json_object_from_request
|
||||
@@ -21,6 +23,8 @@ from synapse.types import UserID
|
||||
|
||||
from .base import ClientV1RestServlet, client_path_patterns
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ProfileDisplaynameRestServlet(ClientV1RestServlet):
|
||||
PATTERNS = client_path_patterns("/profile/(?P<user_id>[^/]*)/displayname")
|
||||
@@ -61,7 +65,10 @@ class ProfileDisplaynameRestServlet(ClientV1RestServlet):
|
||||
user, requester, new_name, is_admin)
|
||||
|
||||
if self.hs.config.shadow_server:
|
||||
self.shadow_displayname(user_id, content)
|
||||
shadow_user = UserID(
|
||||
user.localpart, self.hs.config.shadow_server.get("hs")
|
||||
)
|
||||
self.shadow_displayname(shadow_user.to_string(), content)
|
||||
|
||||
defer.returnValue((200, {}))
|
||||
|
||||
@@ -74,9 +81,9 @@ class ProfileDisplaynameRestServlet(ClientV1RestServlet):
|
||||
shadow_hs_url = self.hs.config.shadow_server.get("hs_url")
|
||||
as_token = self.hs.config.shadow_server.get("as_token")
|
||||
|
||||
yield self.http_client.post_json_get_json(
|
||||
"%s/_matrix/client/r0/profile/%s/displayname?access_token=%s" % (
|
||||
shadow_hs_url, user_id, as_token
|
||||
yield self.http_client.put_json(
|
||||
"%s/_matrix/client/r0/profile/%s/displayname?access_token=%s&user_id=%s" % (
|
||||
shadow_hs_url, user_id, as_token, user_id
|
||||
),
|
||||
body
|
||||
)
|
||||
@@ -120,6 +127,9 @@ class ProfileAvatarURLRestServlet(ClientV1RestServlet):
|
||||
user, requester, new_name, is_admin)
|
||||
|
||||
if self.hs.config.shadow_server:
|
||||
shadow_user = UserID(
|
||||
user.localpart, self.hs.config.shadow_server.get("hs")
|
||||
)
|
||||
self.shadow_avatar_url(user_id, content)
|
||||
|
||||
defer.returnValue((200, {}))
|
||||
@@ -133,9 +143,9 @@ class ProfileAvatarURLRestServlet(ClientV1RestServlet):
|
||||
shadow_hs_url = self.hs.config.shadow_server.get("hs_url")
|
||||
as_token = self.hs.config.shadow_server.get("as_token")
|
||||
|
||||
yield self.http_client.post_json_get_json(
|
||||
"%s/_matrix/client/r0/profile/%s/avatar_url?access_token=%s" % (
|
||||
shadow_hs_url, user_id, as_token
|
||||
yield self.http_client.put_json(
|
||||
"%s/_matrix/client/r0/profile/%s/avatar_url?access_token=%s&user_id=%s" % (
|
||||
shadow_hs_url, shadow_user.to_string(), as_token, user_id
|
||||
),
|
||||
body
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user