This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Split admin API for reported events into a detail and a list view #8539
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d6174a
Split admin API for reported events in detail und list view
dklimpel c672026
add newsfile
dklimpel 8bc62ee
Apply suggestions from code review
dklimpel 11db6da
lint
dklimpel b019eed
Update newsfile, documentation, tests and database functions
dklimpel 1483442
Merge matrix-org/develop
dklimpel cbdc998
Typo an add exception handling
dklimpel 2ae150e
lint
dklimpel dfb36a2
Fix small typo in comment
dklimpel 29e6d83
Update docs/admin_api/event_reports.rst
anoadragon453 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Split admin API for reported events (`GET /_synapse/admin/v1/event_reports`) into detail and list endpoints. This is a breaking change to #8217 which was introduced in synapse v1.21.0. Those who already use this API should check their scripts. Contributed by @dklimpel. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1411,6 +1411,65 @@ async def add_event_report( | |
desc="add_event_report", | ||
) | ||
|
||
async def get_event_report(self, report_id: int) -> Optional[Dict[str, Any]]: | ||
"""Retrieve an event report | ||
|
||
Args: | ||
report_id: ID of reported event in database | ||
Returns: | ||
event_report: json list of information from event report | ||
""" | ||
|
||
def _get_event_report_txn(txn, report_id): | ||
|
||
sql = """ | ||
SELECT | ||
er.id, | ||
er.received_ts, | ||
er.room_id, | ||
er.event_id, | ||
er.user_id, | ||
er.content, | ||
events.sender, | ||
room_stats_state.canonical_alias, | ||
room_stats_state.name, | ||
event_json.json AS event_json | ||
FROM event_reports AS er | ||
LEFT JOIN events | ||
ON events.event_id = er.event_id | ||
JOIN event_json | ||
ON event_json.event_id = er.event_id | ||
JOIN room_stats_state | ||
ON room_stats_state.room_id = er.room_id | ||
WHERE er.id = ? | ||
""" | ||
|
||
txn.execute(sql, [report_id]) | ||
row = txn.fetchone() | ||
|
||
if not row: | ||
return None | ||
|
||
event_report = { | ||
"id": row[0], | ||
"received_ts": row[1], | ||
"room_id": row[2], | ||
"event_id": row[3], | ||
"user_id": row[4], | ||
"score": db_to_json(row[5]).get("score"), | ||
"reason": db_to_json(row[5]).get("reason"), | ||
"sender": row[6], | ||
"canonical_alias": row[7], | ||
"name": row[8], | ||
"event_json": db_to_json(row[9]), | ||
} | ||
|
||
return event_report | ||
|
||
return await self.db_pool.runInteraction( | ||
"get_event_report", _get_event_report_txn, report_id | ||
) | ||
|
||
async def get_event_reports_paginate( | ||
self, | ||
start: int, | ||
|
@@ -1468,18 +1527,15 @@ def _get_event_reports_paginate_txn(txn): | |
er.room_id, | ||
er.event_id, | ||
er.user_id, | ||
er.reason, | ||
er.content, | ||
events.sender, | ||
room_aliases.room_alias, | ||
event_json.json AS event_json | ||
room_stats_state.canonical_alias, | ||
room_stats_state.name | ||
FROM event_reports AS er | ||
LEFT JOIN room_aliases | ||
ON room_aliases.room_id = er.room_id | ||
JOIN events | ||
LEFT JOIN events | ||
ON events.event_id = er.event_id | ||
JOIN event_json | ||
ON event_json.event_id = er.event_id | ||
JOIN room_stats_state | ||
ON room_stats_state.room_id = er.room_id | ||
{where_clause} | ||
ORDER BY er.received_ts {order} | ||
LIMIT ? | ||
|
@@ -1490,15 +1546,24 @@ def _get_event_reports_paginate_txn(txn): | |
|
||
args += [limit, start] | ||
txn.execute(sql, args) | ||
event_reports = self.db_pool.cursor_to_dict(txn) | ||
|
||
event_reports = [] | ||
if count > 0: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
for row in event_reports: | ||
try: | ||
row["content"] = db_to_json(row["content"]) | ||
row["event_json"] = db_to_json(row["event_json"]) | ||
except Exception: | ||
continue | ||
for row in txn: | ||
event_reports.append( | ||
{ | ||
"id": row[0], | ||
"received_ts": row[1], | ||
"room_id": row[2], | ||
"event_id": row[3], | ||
"user_id": row[4], | ||
"score": db_to_json(row[5]).get("score"), | ||
"reason": db_to_json(row[5]).get("reason"), | ||
"sender": row[6], | ||
"canonical_alias": row[7], | ||
"name": row[8], | ||
} | ||
) | ||
|
||
return event_reports, count | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.