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

Commit

Permalink
Make EventHandler.get_event return None when the requested event …
Browse files Browse the repository at this point in the history
…is not found (#15298)
  • Loading branch information
anoadragon453 authored Mar 21, 2023
1 parent f11fe93 commit b6aef59
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/15298.bugfix
Original file line number Diff line number Diff line change
@@ -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).
9 changes: 5 additions & 4 deletions synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,16 @@ async def get_event(
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:
Expand Down
5 changes: 5 additions & 0 deletions tests/rest/client/test_report_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def test_cannot_report_nonexistent_event(self) -> None:
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(
Expand Down

0 comments on commit b6aef59

Please sign in to comment.