Admin API endpoint to delete a reported event (#15116)

* Admin api to delete event report

* lint +  tests

* newsfile

* Apply suggestions from code review

Co-authored-by: David Robertson <david.m.robertson1@gmail.com>

* revert changes - move to WorkerStore

* update unit test

* Note that timestamp is in millseconds

---------

Co-authored-by: David Robertson <david.m.robertson1@gmail.com>
This commit is contained in:
Dirk Klimpel 2023-02-28 13:09:10 +01:00 committed by GitHub
parent 1cd4fbc51d
commit 93f7955eba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 224 additions and 11 deletions

View file

@ -1417,6 +1417,27 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
get_un_partial_stated_rooms_from_stream_txn,
)
async def delete_event_report(self, report_id: int) -> bool:
"""Remove an event report from database.
Args:
report_id: Report to delete
Returns:
Whether the report was successfully deleted or not.
"""
try:
await self.db_pool.simple_delete_one(
table="event_reports",
keyvalues={"id": report_id},
desc="delete_event_report",
)
except StoreError:
# Deletion failed because report does not exist
return False
return True
class _BackgroundUpdates:
REMOVE_TOMESTONED_ROOMS_BG_UPDATE = "remove_tombstoned_rooms_from_directory"
@ -2139,7 +2160,19 @@ class RoomStore(RoomBackgroundUpdateStore, RoomWorkerStore):
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 (milliseconds).
Returns:
Id of the event report.
"""
next_id = self._event_reports_id_gen.get_next()
await self.db_pool.simple_insert(
table="event_reports",
@ -2154,6 +2187,7 @@ class RoomStore(RoomBackgroundUpdateStore, RoomWorkerStore):
},
desc="add_event_report",
)
return next_id
async def get_event_report(self, report_id: int) -> Optional[Dict[str, Any]]:
"""Retrieve an event report