Skip to content
This repository has been 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 4 commits
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
1 change: 1 addition & 0 deletions changelog.d/15116.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add admin API to delete a reported event.
dklimpel marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions docs/admin_api/event_reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,17 @@ The following fields are returned in the JSON response body:
* `canonical_alias`: string - The canonical alias of the room. `null` if the room does not
have a canonical alias set.
* `event_json`: object - Details of the original event that was reported.

# Delete a specific event report

This API deletes a specific event report. If the request is successful, the response body
will be an empty JSON object.

The api is:
```
DELETE /_synapse/admin/v1/event_reports/<report_id>
```

**URL parameters:**

* `report_id`: string - The ID of the event report.
41 changes: 33 additions & 8 deletions synapse/rest/admin/event_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class EventReportsRestServlet(RestServlet):
PATTERNS = admin_patterns("/event_reports$")

def __init__(self, hs: "HomeServer"):
self.auth = hs.get_auth()
self.store = hs.get_datastores().main
self._auth = hs.get_auth()
self._store = hs.get_datastores().main

async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
await assert_requester_is_admin(self.auth, request)
await assert_requester_is_admin(self._auth, request)

start = parse_integer(request, "from", default=0)
limit = parse_integer(request, "limit", default=100)
Expand All @@ -79,7 +79,7 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
errcode=Codes.INVALID_PARAM,
)

event_reports, total = await self.store.get_event_reports_paginate(
event_reports, total = await self._store.get_event_reports_paginate(
start, limit, direction, user_id, room_id
)
ret = {"event_reports": event_reports, "total": total}
Expand Down Expand Up @@ -108,13 +108,13 @@ class EventReportDetailRestServlet(RestServlet):
PATTERNS = admin_patterns("/event_reports/(?P<report_id>[^/]*)$")

def __init__(self, hs: "HomeServer"):
self.auth = hs.get_auth()
self.store = hs.get_datastores().main
self._auth = hs.get_auth()
self._store = hs.get_datastores().main

async def on_GET(
self, request: SynapseRequest, report_id: str
) -> Tuple[int, JsonDict]:
await assert_requester_is_admin(self.auth, request)
await assert_requester_is_admin(self._auth, request)

message = (
"The report_id parameter must be a string representing a positive integer."
Expand All @@ -131,8 +131,33 @@ async def on_GET(
HTTPStatus.BAD_REQUEST, message, errcode=Codes.INVALID_PARAM
)

ret = await self.store.get_event_report(resolved_report_id)
ret = await self._store.get_event_report(resolved_report_id)
if not ret:
raise NotFoundError("Event report not found")

return HTTPStatus.OK, ret

async def on_DELETE(
self, request: SynapseRequest, report_id: str
) -> Tuple[int, JsonDict]:
await assert_requester_is_admin(self._auth, request)

message = (
"The report_id parameter must be a string representing a positive integer."
)
try:
resolved_report_id = int(report_id)
except ValueError:
raise SynapseError(
HTTPStatus.BAD_REQUEST, message, errcode=Codes.INVALID_PARAM
)

if resolved_report_id < 0:
raise SynapseError(
HTTPStatus.BAD_REQUEST, message, errcode=Codes.INVALID_PARAM
)

if await self._store.delete_event_report(resolved_report_id):
return HTTPStatus.OK, {}

raise NotFoundError("Event report not found")
Loading