Skip to content
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

Add the ability to filter by state event type on admin room state endpoint #18035

Merged
merged 6 commits into from
Jan 8, 2025
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
4 changes: 2 additions & 2 deletions changelog.d/18035.feature
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Adds a query param `type` to `/_synapse/admin/v1/rooms/{room_id}/state` that filters the state event
query by state event type.
Add a query param `type` to the [Room State Admin API](https://element-hq.github.io/synapse/develop/admin_api/rooms.html#room-state-api)
that filters the state event.
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ GET /_synapse/admin/v1/rooms/<room_id>/state
The following query parameter is available:

* `type` - The type of room state event to filter by, eg "m.room.create". If provided, only state events
of this type will be returned.
of this type will be returned (regardless of their `state_key` value).

A response body like the following is returned:

Expand Down
5 changes: 0 additions & 5 deletions synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,6 @@ async def on_GET(
type = parse_string(request, "type")

if type:
if not type.startswith("m.room."):
raise SynapseError(
HTTPStatus.BAD_REQUEST,
"Type must be a room state event.",
)
state_filter = StateFilter(
types=immutabledict({type: None}),
include_others=False,
Expand Down
26 changes: 22 additions & 4 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -2052,16 +2052,34 @@ def test_room_state_param(self) -> None:
self.assertEqual(event["type"], "m.room.member")
self.assertEqual(event["state_key"], self.admin_user)

def test_room_state_bad_param(self) -> None:
"""Test that request with param not conforming to 'm.room.*' will be rejected"""
def test_room_state_param_empty(self) -> None:
"""Test that passing an empty string as state filter param returns no state events"""
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)

channel = self.make_request(
"GET",
f"/_synapse/admin/v1/rooms/{room_id}/state?type=m.something.else",
f"/_synapse/admin/v1/rooms/{room_id}/state?type=''",
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
access_token=self.admin_user_tok,
)
self.assertEqual(400, channel.code)
self.assertEqual(200, channel.code)
state = channel.json_body["state"]
self.assertEqual(0, len(state))

def test_room_state_param_not_in_room(self) -> None:
"""
Test that passing a state filter param for a state event not in the room
returns no state events
"""
room_id = self.helper.create_room_as(self.admin_user, tok=self.admin_user_tok)

channel = self.make_request(
"GET",
f"/_synapse/admin/v1/rooms/{room_id}/state?type=m.room.custom",
access_token=self.admin_user_tok,
)
self.assertEqual(200, channel.code)
state = channel.json_body["state"]
self.assertEqual(0, len(state))

H-Shay marked this conversation as resolved.
Show resolved Hide resolved
def _set_canonical_alias(
self, room_id: str, test_alias: str, admin_user_tok: str
Expand Down
Loading