Fix messages from multiple senders in historical chunk
Follow-up to https://github.com/matrix-org/synapse/pull/9247 Part of MSC2716: https://github.com/matrix-org/matrix-doc/pull/2716 --- Previously, Synapse would throw a 403, `Cannot force another user to join.`, because we were trying to use `?user_id` from a single virtual user which did not match with messages from other users in the chunk.pull/10419/head
parent
38bcf13e1e
commit
e405a23f48
|
@ -342,7 +342,17 @@ def _is_membership_change_allowed(
|
||||||
# * They are accepting a previously sent invitation.
|
# * They are accepting a previously sent invitation.
|
||||||
# * They are already joined (it's a NOOP).
|
# * They are already joined (it's a NOOP).
|
||||||
# * The room is public or restricted.
|
# * The room is public or restricted.
|
||||||
|
logger.info(
|
||||||
|
"check join aewffaewafewf %s %s",
|
||||||
|
event.user_id,
|
||||||
|
target_user_id,
|
||||||
|
)
|
||||||
if event.user_id != target_user_id:
|
if event.user_id != target_user_id:
|
||||||
|
logger.error(
|
||||||
|
"Cannot force another user to join aewffaewafewf %s %s",
|
||||||
|
event.user_id,
|
||||||
|
target_user_id,
|
||||||
|
)
|
||||||
raise AuthError(403, "Cannot force another user to join.")
|
raise AuthError(403, "Cannot force another user to join.")
|
||||||
elif target_banned:
|
elif target_banned:
|
||||||
raise AuthError(403, "You are banned from this room")
|
raise AuthError(403, "You are banned from this room")
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
""" This module contains REST servlets to do with rooms: /rooms/<paths> """
|
""" This module contains REST servlets to do with rooms: /rooms/<paths> """
|
||||||
|
import copy
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple
|
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple
|
||||||
|
@ -47,6 +48,7 @@ from synapse.storage.state import StateFilter
|
||||||
from synapse.streams.config import PaginationConfig
|
from synapse.streams.config import PaginationConfig
|
||||||
from synapse.types import (
|
from synapse.types import (
|
||||||
JsonDict,
|
JsonDict,
|
||||||
|
Requester,
|
||||||
RoomAlias,
|
RoomAlias,
|
||||||
RoomID,
|
RoomID,
|
||||||
StreamToken,
|
StreamToken,
|
||||||
|
@ -309,7 +311,14 @@ class RoomBatchSendEventRestServlet(TransactionRestServlet):
|
||||||
self.room_member_handler = hs.get_room_member_handler()
|
self.room_member_handler = hs.get_room_member_handler()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
|
|
||||||
async def inherit_depth_from_prev_ids(self, prev_event_ids) -> int:
|
def _copy_requester_and_override_user_id(self, requester, new_user_id):
|
||||||
|
serialized_requester = requester.serialize()
|
||||||
|
serialized_requester["user_id"] = new_user_id
|
||||||
|
new_requester = Requester.deserialize(self.store, serialized_requester)
|
||||||
|
|
||||||
|
return new_requester
|
||||||
|
|
||||||
|
async def _inherit_depth_from_prev_ids(self, prev_event_ids) -> int:
|
||||||
(
|
(
|
||||||
most_recent_prev_event_id,
|
most_recent_prev_event_id,
|
||||||
most_recent_prev_event_depth,
|
most_recent_prev_event_depth,
|
||||||
|
@ -438,7 +447,9 @@ class RoomBatchSendEventRestServlet(TransactionRestServlet):
|
||||||
if event_dict["type"] == EventTypes.Member:
|
if event_dict["type"] == EventTypes.Member:
|
||||||
membership = event_dict["content"].get("membership", None)
|
membership = event_dict["content"].get("membership", None)
|
||||||
event_id, _ = await self.room_member_handler.update_membership(
|
event_id, _ = await self.room_member_handler.update_membership(
|
||||||
requester,
|
self._copy_requester_and_override_user_id(
|
||||||
|
requester, state_event["sender"]
|
||||||
|
),
|
||||||
target=UserID.from_string(event_dict["state_key"]),
|
target=UserID.from_string(event_dict["state_key"]),
|
||||||
room_id=room_id,
|
room_id=room_id,
|
||||||
action=membership,
|
action=membership,
|
||||||
|
@ -458,7 +469,9 @@ class RoomBatchSendEventRestServlet(TransactionRestServlet):
|
||||||
event,
|
event,
|
||||||
_,
|
_,
|
||||||
) = await self.event_creation_handler.create_and_send_nonmember_event(
|
) = await self.event_creation_handler.create_and_send_nonmember_event(
|
||||||
requester,
|
self._copy_requester_and_override_user_id(
|
||||||
|
requester, state_event["sender"]
|
||||||
|
),
|
||||||
event_dict,
|
event_dict,
|
||||||
outlier=True,
|
outlier=True,
|
||||||
prev_event_ids=[fake_prev_event_id],
|
prev_event_ids=[fake_prev_event_id],
|
||||||
|
@ -510,7 +523,9 @@ class RoomBatchSendEventRestServlet(TransactionRestServlet):
|
||||||
# Prepend the insertion event to the start of the chunk
|
# Prepend the insertion event to the start of the chunk
|
||||||
events_to_create = [insertion_event] + events_to_create
|
events_to_create = [insertion_event] + events_to_create
|
||||||
|
|
||||||
inherited_depth = await self.inherit_depth_from_prev_ids(prev_events_from_query)
|
inherited_depth = await self._inherit_depth_from_prev_ids(
|
||||||
|
prev_events_from_query
|
||||||
|
)
|
||||||
|
|
||||||
event_ids = []
|
event_ids = []
|
||||||
prev_event_ids = prev_events_from_query
|
prev_event_ids = prev_events_from_query
|
||||||
|
@ -532,7 +547,7 @@ class RoomBatchSendEventRestServlet(TransactionRestServlet):
|
||||||
}
|
}
|
||||||
|
|
||||||
event, context = await self.event_creation_handler.create_event(
|
event, context = await self.event_creation_handler.create_event(
|
||||||
requester,
|
self._copy_requester_and_override_user_id(requester, ev["sender"]),
|
||||||
event_dict,
|
event_dict,
|
||||||
prev_event_ids=event_dict.get("prev_events"),
|
prev_event_ids=event_dict.get("prev_events"),
|
||||||
auth_event_ids=auth_event_ids,
|
auth_event_ids=auth_event_ids,
|
||||||
|
@ -562,7 +577,7 @@ class RoomBatchSendEventRestServlet(TransactionRestServlet):
|
||||||
# where topological_ordering is just depth.
|
# where topological_ordering is just depth.
|
||||||
for (event, context) in reversed(events_to_persist):
|
for (event, context) in reversed(events_to_persist):
|
||||||
ev = await self.event_creation_handler.handle_new_client_event(
|
ev = await self.event_creation_handler.handle_new_client_event(
|
||||||
requester=requester,
|
self._copy_requester_and_override_user_id(requester, event["sender"]),
|
||||||
event=event,
|
event=event,
|
||||||
context=context,
|
context=context,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue