Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit b6aef59

Browse files
Make EventHandler.get_event return None when the requested event is not found (#15298)
1 parent f11fe93 commit b6aef59

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

changelog.d/15298.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a bug in which the [`POST /_matrix/client/v3/rooms/{roomId}/report/{eventId}`](https://spec.matrix.org/v1.6/client-server-api/#post_matrixclientv3roomsroomidreporteventid) endpoint would return the wrong error if the user did not have permission to view the event. This aligns Synapse's implementation with [MSC2249](https://github.com/matrix-org/matrix-spec-proposals/pull/2249).

synapse/handlers/events.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,16 @@ async def get_event(
159159
Returns:
160160
An event, or None if there is no event matching this ID.
161161
Raises:
162-
SynapseError if there was a problem retrieving this event, or
163-
AuthError if the user does not have the rights to inspect this
164-
event.
162+
AuthError: if the user does not have the rights to inspect this event.
165163
"""
166164
redact_behaviour = (
167165
EventRedactBehaviour.as_is if show_redacted else EventRedactBehaviour.redact
168166
)
169167
event = await self.store.get_event(
170-
event_id, check_room_id=room_id, redact_behaviour=redact_behaviour
168+
event_id,
169+
check_room_id=room_id,
170+
redact_behaviour=redact_behaviour,
171+
allow_none=True,
171172
)
172173

173174
if not event:

tests/rest/client/test_report_event.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ def test_cannot_report_nonexistent_event(self) -> None:
8484
access_token=self.other_user_tok,
8585
)
8686
self.assertEqual(404, channel.code, msg=channel.result["body"])
87+
self.assertEqual(
88+
"Unable to report event: it does not exist or you aren't able to see it.",
89+
channel.json_body["error"],
90+
msg=channel.result["body"],
91+
)
8792

8893
def _assert_status(self, response_status: int, data: JsonDict) -> None:
8994
channel = self.make_request(

0 commit comments

Comments
 (0)