diff options
author | Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> | 2023-03-21 13:23:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-21 13:23:47 +0000 |
commit | b6aef593347924d39b4ff8b07e375eb656001545 (patch) | |
tree | 3f7642647b8e184b21067834bcb4a89abc5a34a6 | |
parent | Document that our Docker images are mirrored to GHCR. (#15282) (diff) | |
download | synapse-b6aef593347924d39b4ff8b07e375eb656001545.tar.xz |
Make `EventHandler.get_event` return `None` when the requested event is not found (#15298)
-rw-r--r-- | changelog.d/15298.bugfix | 1 | ||||
-rw-r--r-- | synapse/handlers/events.py | 9 | ||||
-rw-r--r-- | tests/rest/client/test_report_event.py | 5 |
3 files changed, 11 insertions, 4 deletions
diff --git a/changelog.d/15298.bugfix b/changelog.d/15298.bugfix new file mode 100644 index 0000000000..8f29b08444 --- /dev/null +++ b/changelog.d/15298.bugfix @@ -0,0 +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). \ No newline at end of file diff --git a/synapse/handlers/events.py b/synapse/handlers/events.py index 68c07f0265..33359f6ed7 100644 --- a/synapse/handlers/events.py +++ b/synapse/handlers/events.py @@ -159,15 +159,16 @@ class EventHandler: Returns: An event, or None if there is no event matching this ID. Raises: - SynapseError if there was a problem retrieving this event, or - AuthError if the user does not have the rights to inspect this - event. + AuthError: if the user does not have the rights to inspect this event. """ redact_behaviour = ( EventRedactBehaviour.as_is if show_redacted else EventRedactBehaviour.redact ) event = await self.store.get_event( - event_id, check_room_id=room_id, redact_behaviour=redact_behaviour + event_id, + check_room_id=room_id, + redact_behaviour=redact_behaviour, + allow_none=True, ) if not event: diff --git a/tests/rest/client/test_report_event.py b/tests/rest/client/test_report_event.py index 1250685d39..1a8ab067a9 100644 --- a/tests/rest/client/test_report_event.py +++ b/tests/rest/client/test_report_event.py @@ -84,6 +84,11 @@ class ReportEventTestCase(unittest.HomeserverTestCase): access_token=self.other_user_tok, ) self.assertEqual(404, channel.code, msg=channel.result["body"]) + self.assertEqual( + "Unable to report event: it does not exist or you aren't able to see it.", + channel.json_body["error"], + msg=channel.result["body"], + ) def _assert_status(self, response_status: int, data: JsonDict) -> None: channel = self.make_request( |