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

Admin API endpoint to delete a reported event #15116

Merged
merged 8 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -2160,7 +2160,19 @@ async def add_event_report(
reason: Optional[str],
content: JsonDict,
received_ts: int,
) -> None:
) -> int:
"""Add an event report

Args:
room_id: Room that contains the reported event.
event_id: The reported event.
user_id: User who reports the event.
reason: Description that the user specifies.
content: Report request body (score and reason).
received_ts: Time when the user submitted the report.
Returns:
Id of the event report.
"""
next_id = self._event_reports_id_gen.get_next()
await self.db_pool.simple_insert(
table="event_reports",
Expand All @@ -2175,6 +2187,7 @@ async def add_event_report(
},
desc="add_event_report",
)
return next_id

async def get_event_report(self, report_id: int) -> Optional[Dict[str, Any]]:
"""Retrieve an event report
Expand Down
15 changes: 12 additions & 3 deletions tests/rest/admin/test_event_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
self.other_user_tok = self.login("user", "pass")

# create report
self.get_success(
event_id = self.get_success(
self._store.add_event_report(
"room_id",
"event_id",
Expand All @@ -628,8 +628,7 @@ def prepare(self, reactor: MemoryReactor, clock: Clock, hs: HomeServer) -> None:
)
)

# first created event report gets `id`=2
self.url = "/_synapse/admin/v1/event_reports/2"
self.url = f"/_synapse/admin/v1/event_reports/{event_id}"

def test_no_auth(self) -> None:
"""
Expand Down Expand Up @@ -668,6 +667,16 @@ def test_delete_success(self) -> None:
self.assertEqual(200, channel.code, msg=channel.json_body)
self.assertEqual({}, channel.json_body)

channel = self.make_request(
"GET",
self.url,
access_token=self.admin_user_tok,
)

# check that report was deleted
self.assertEqual(404, channel.code, msg=channel.json_body)
self.assertEqual(Codes.NOT_FOUND, channel.json_body["errcode"])

def test_invalid_report_id(self) -> None:
"""
Testing that an invalid `report_id` returns a 400.
Expand Down