Skip to content

Add admin API for fetching room reports #18253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

turt2live
Copy link
Member

@turt2live turt2live commented Mar 18, 2025

Very much a copy/paste of the event reporting API: https://element-hq.github.io/synapse/latest/admin_api/event_reports.html

Differences:

  • No sender or sender filtering - rooms don't have senders.
  • No get individual report detail API - there are other APIs for getting room details (which are the relevant parts of a report anyway).
  • No delete individual report API - just isn't needed at this stage. A future PR/contributor can add one.
  • No score - there isn't any.
  • No event_id - there isn't any.

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Code style is correct
    (run the linters)

@turt2live turt2live requested a review from a team as a code owner March 18, 2025 21:37
@github-actions github-actions bot deployed to PR Documentation Preview March 18, 2025 21:39 Active
@github-actions github-actions bot deployed to PR Documentation Preview March 18, 2025 21:43 Active
@reivilibre
Copy link
Contributor

@turt2live the trial unit tests are failing FWIW

@turt2live
Copy link
Member Author

I'm not seeing errors which look related to this PR. Is there somewhere else I should be looking?

@github-actions github-actions bot deployed to PR Documentation Preview May 2, 2025 09:52 Active
Copy link
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor things, but on the whole looks good! Tests are failing due to this PR though, see below.

"""Report a room"""
channel = self.make_request(
"POST",
"rooms/%s/report" % room_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test failure logs can be seen here.

The shorthand form doesn't actually work here, as it prepends /_matrix/client/r0/:

synapse/tests/server.py

Lines 412 to 420 in 10812bc

# Decorate it to be the full path, if we're using shorthand
if (
shorthand
and not path.startswith(b"/_matrix")
and not path.startswith(b"/_synapse")
):
if path.startswith(b"/"):
path = path[1:]
path = b"/_matrix/client/r0/" + path

whereas /rooms/{roomId}/report only listens on v3:

class ReportRoomRestServlet(RestServlet):
"""This endpoint lets clients report a room for abuse.
Introduced by MSC4151: https://github.com/matrix-org/matrix-spec-proposals/pull/4151
"""
# Cast the Iterable to a list so that we can `append` below.
PATTERNS = list(
client_patterns(
"/rooms/(?P<room_id>[^/]*)/report$",
releases=("v3",),
unstable=False,
v1=False,
)
)

I'd recommend putting the full path to avoid the shorthand logic:

Suggested change
"rooms/%s/report" % room_id,
f"/_matrix/client/v3/rooms/{room_id}/report",

"""Report a room, but omit reason"""
channel = self.make_request(
"POST",
"rooms/%s/report" % room_id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"rooms/%s/report" % room_id,
f"/_matrix/client/v3/rooms/{room_id}/report",

```

To paginate, check for `next_token` and if present, call the endpoint again with `from`
set to the value of `next_token`. This will return a new page.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set to the value of `next_token`. This will return a new page.
set to the value of `next_token` and the same `limit`. This will return a new page.

If the endpoint does not return a `next_token` then there are no more reports to
paginate through.

**URL parameters:**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
**URL parameters:**
**Query parameters:**

Comment on lines +14 to +18
# Originally licensed under the Apache License, Version 2.0:
# <http://www.apache.org/licenses/LICENSE-2.0>.
#
# [This file includes modifications made by New Vector Limited]
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a new file, this section isn't needed.

Suggested change
# Originally licensed under the Apache License, Version 2.0:
# <http://www.apache.org/licenses/LICENSE-2.0>.
#
# [This file includes modifications made by New Vector Limited]
#

self.assertIn("user_id", c)
self.assertIn("canonical_alias", c)
self.assertIn("name", c)
self.assertIn("reason", c)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure we don't accidentally introduce another field (since we're taking raw output from a database storage function:

Suggested change
self.assertIn("reason", c)
self.assertIn("reason", c)
self.assertEqual(len(c.keys()), 7)

Comment on lines +13 to +18
#
# Originally licensed under the Apache License, Version 2.0:
# <http://www.apache.org/licenses/LICENSE-2.0>.
#
# [This file includes modifications made by New Vector Limited]
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#
# Originally licensed under the Apache License, Version 2.0:
# <http://www.apache.org/licenses/LICENSE-2.0>.
#
# [This file includes modifications made by New Vector Limited]
#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants