Allow 3rd party rules check_event_allowed callback to function for room version "12" creation events (#19768)

This commit is contained in:
Jason Little
2026-09-15 11:15:23 +00:00
committed by GitHub
parent 177f8b5b76
commit ac771446a6
2 changed files with 27 additions and 9 deletions
+1
View File
@@ -0,0 +1 @@
Allow the Third Party Rules `check_event_allowed()` callback to work with [MSC4291](https://github.com/matrix-org/matrix-spec-proposals/pull/4291) rooms. Contributed by @famedly.
+26 -9
View File
@@ -2449,11 +2449,15 @@ class EventCreationHandler:
original_event.room_version, third_party_result
)
self.validator.validate_builder(builder)
assert builder.room_id is not None
except SynapseError as e:
raise Exception(
"Third party rules module created an invalid event: " + e.msg,
)
# Prepend the error message with some context. This will be raised as a
# `400` since assumption of the validator is that it came directly from a
# client. Change this to a `500`, as the module will have changed something
# and that is a fault of the server
e.msg = "Third party rules module created an invalid event: " + e.msg
e.code = HTTPStatus.INTERNAL_SERVER_ERROR
raise
immutable_fields = [
# changing the room is going to break things: we've already checked that the
@@ -2484,12 +2488,25 @@ class EventCreationHandler:
for k, v in original_event.internal_metadata.get_dict().items():
setattr(builder.internal_metadata, k, v)
# modules can send new state events, so we re-calculate the auth events just in
# case.
prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
# Creation events using msc4242 and msc4291 rooms will not have a room_id, and
# will also not have prev_events nor prev_state_events(below).
prev_event_ids = []
if builder.room_id is not None and not (
builder.type == EventTypes.Create
and original_event.room_version.msc4291_room_ids_as_hashes
):
prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
prev_state_events = None
if original_event.room_version.msc4242_state_dags:
prev_state_events: list[str] | None = (
[] if original_event.room_version.msc4242_state_dags else None
)
if (
original_event.room_version.msc4242_state_dags
and builder.type != EventTypes.Create
and builder.room_id is not None
):
# modules can send new state events, so we re-calculate the auth events just
# in case.
prev_state_events = list(
await self.store.get_state_dag_extremities(builder.room_id)
)