Don't spam check actions by admins

This commit is contained in:
Erik Johnston 2019-03-18 15:44:37 +00:00
parent e64f7c0188
commit feae387576
2 changed files with 43 additions and 12 deletions

View file

@ -81,6 +81,8 @@ class RoomCreationHandler(BaseHandler):
# linearizer to stop two upgrades happening at once # linearizer to stop two upgrades happening at once
self._upgrade_linearizer = Linearizer("room_upgrade_linearizer") self._upgrade_linearizer = Linearizer("room_upgrade_linearizer")
self._server_notices_mxid = hs.config.server_notices_mxid
@defer.inlineCallbacks @defer.inlineCallbacks
def upgrade_room(self, requester, old_room_id, new_version): def upgrade_room(self, requester, old_room_id, new_version):
"""Replace a room with a new room with a different version """Replace a room with a new room with a different version
@ -254,7 +256,17 @@ class RoomCreationHandler(BaseHandler):
""" """
user_id = requester.user.to_string() user_id = requester.user.to_string()
if not self.spam_checker.user_may_create_room( if (self._server_notices_mxid is not None and
requester.user.to_string() == self._server_notices_mxid):
# allow the server notices mxid to create rooms
is_requester_admin = True
else:
is_requester_admin = yield self.auth.is_server_admin(
requester.user,
)
if not is_requester_admin and not self.spam_checker.user_may_create_room(
user_id, user_id,
invite_list=[], invite_list=[],
cloning=True, cloning=True,
@ -481,7 +493,16 @@ class RoomCreationHandler(BaseHandler):
invite_list = config.get("invite", []) invite_list = config.get("invite", [])
if not self.spam_checker.user_may_create_room( if (self._server_notices_mxid is not None and
requester.user.to_string() == self._server_notices_mxid):
# allow the server notices mxid to create rooms
is_requester_admin = True
else:
is_requester_admin = yield self.auth.is_server_admin(
requester.user,
)
if not is_requester_admin and not self.spam_checker.user_may_create_room(
user_id, user_id,
invite_list=invite_list, invite_list=invite_list,
cloning=False, cloning=False,

View file

@ -487,13 +487,23 @@ class RoomMemberHandler(object):
# so don't really fit into the general auth process. # so don't really fit into the general auth process.
raise AuthError(403, "Guest access not allowed") raise AuthError(403, "Guest access not allowed")
if (self._server_notices_mxid is not None and
requester.user.to_string() == self._server_notices_mxid):
# allow the server notices mxid to join rooms
is_requester_admin = True
else:
is_requester_admin = yield self.auth.is_server_admin(
requester.user,
)
inviter = yield self._get_inviter(target.to_string(), room_id) inviter = yield self._get_inviter(target.to_string(), room_id)
if not is_requester_admin:
# We assume that if the spam checker allowed the user to create # We assume that if the spam checker allowed the user to create
# a room then they're allowed to join it. # a room then they're allowed to join it.
if not new_room and not self.spam_checker.user_may_join_room( if not new_room and not self.spam_checker.user_may_join_room(
target.to_string(), room_id, target.to_string(), room_id,
is_invited=inviter is not None, is_invited=inviter is not None,
new_room=new_room,
): ):
raise SynapseError( raise SynapseError(
403, "Not allowed to join this room", 403, "Not allowed to join this room",