diff --git a/docs/admin_api/rooms.md b/docs/admin_api/rooms.md index 03f990bba80..8e3a367e90a 100644 --- a/docs/admin_api/rooms.md +++ b/docs/admin_api/rooms.md @@ -36,8 +36,10 @@ The following query parameters are available: - the room's name, - the local part of the room's canonical alias, or - the complete (local and server part) room's id (case sensitive). -* `filter_public_rooms` - Flag to filter public and non-public rooms. -* `filter_empty_rooms` - Flag to filter empty and non-empty rooms. A room is empty if joined_members is zero. +* `public_rooms` - Optional flag to filter public rooms. If `true`, only public rooms are queried. If `false`, public rooms are excluded from + the query. When the flag is absent (the default), **both** public and non-public rooms are included in the search results. +* `empty_rooms` - Optional flag to filter empty rooms. A room is empty if joined_members is zero. If `true`, only empty rooms are queried. If `false`, empty rooms are excluded from + the query. When the flag is absent (the default), **both** empty and non-empty rooms are included in the search results. Defaults to no filtering. diff --git a/synapse/rest/admin/rooms.py b/synapse/rest/admin/rooms.py index bbbca32f7b8..01f9de9ffa5 100644 --- a/synapse/rest/admin/rooms.py +++ b/synapse/rest/admin/rooms.py @@ -243,24 +243,22 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]: errcode=Codes.INVALID_PARAM, ) - filter_public_rooms = parse_boolean(request, "filter_public_rooms") - filter_empty_rooms = parse_boolean(request, "filter_empty_rooms") + public_rooms = parse_boolean(request, "public_rooms") + empty_rooms = parse_boolean(request, "empty_rooms") direction = parse_enum(request, "dir", Direction, default=Direction.FORWARDS) reverse_order = True if direction == Direction.BACKWARDS else False - try: - # Return list of rooms according to parameters - rooms, total_rooms = await self.store.get_rooms_paginate( - start, - limit, - order_by, - reverse_order, - search_term, - filter_public_rooms, - filter_empty_rooms, - ) - except Exception as e: - print(e) + + # Return list of rooms according to parameters + rooms, total_rooms = await self.store.get_rooms_paginate( + start, + limit, + order_by, + reverse_order, + search_term, + public_rooms, + empty_rooms, + ) response = { # next_token should be opaque, so return a value the client can parse diff --git a/synapse/storage/databases/main/room.py b/synapse/storage/databases/main/room.py index a3f094a968c..4972aef303c 100644 --- a/synapse/storage/databases/main/room.py +++ b/synapse/storage/databases/main/room.py @@ -606,8 +606,8 @@ async def get_rooms_paginate( order_by: str, reverse_order: bool, search_term: Optional[str], - filter_public_rooms: Optional[bool], - filter_empty_rooms: Optional[bool], + public_rooms: Optional[bool], + empty_rooms: Optional[bool], ) -> Tuple[List[Dict[str, Any]], int]: """Function to retrieve a paginated list of rooms as json. @@ -619,10 +619,10 @@ async def get_rooms_paginate( search_term: a string to filter room names, canonical alias and room ids by. Room ID must match exactly. Canonical alias must match a substring of the local part. - filter_public_rooms: Optional flag to filter public and non-public rooms. If true, public rooms are queried. + public_rooms: Optional flag to filter public and non-public rooms. If true, public rooms are queried. if false, public rooms are excluded from the query. When it is none (the default), both public rooms and none-public-rooms are queried. - filter_empty_rooms: Optional flag to filter empty and non-empty rooms. + empty_rooms: Optional flag to filter empty and non-empty rooms. A room is empty if joined_members is zero. If true, empty rooms are queried. if false, empty rooms are excluded from the query. When it is @@ -651,12 +651,12 @@ async def get_rooms_paginate( f"#%{search_term.lower()}%:%", search_term, ] - if filter_public_rooms is not None: - filter_arg = "1" if filter_public_rooms else "0" + if public_rooms is not None: + filter_arg = "1" if public_rooms else "0" filter_.append(f"rooms.is_public = '{filter_arg}'") - if filter_empty_rooms is not None: - if filter_empty_rooms: + if empty_rooms is not None: + if empty_rooms: filter_.append("curr.joined_members = 0") else: filter_.append("curr.joined_members <> 0") diff --git a/tests/rest/admin/test_room.py b/tests/rest/admin/test_room.py index 5559ccccdc1..95ed7364510 100644 --- a/tests/rest/admin/test_room.py +++ b/tests/rest/admin/test_room.py @@ -1817,7 +1817,7 @@ def test_filter_public_rooms(self) -> None: response = self.make_request( "GET", - "/_synapse/admin/v1/rooms?filter_public_rooms=true", + "/_synapse/admin/v1/rooms?public_rooms=true", access_token=self.admin_user_tok, ) self.assertEqual(200, response.code, msg=response.json_body) @@ -1826,7 +1826,7 @@ def test_filter_public_rooms(self) -> None: response = self.make_request( "GET", - "/_synapse/admin/v1/rooms?filter_public_rooms=false", + "/_synapse/admin/v1/rooms?public_rooms=false", access_token=self.admin_user_tok, ) self.assertEqual(200, response.code, msg=response.json_body) @@ -1856,7 +1856,7 @@ def test_filter_empty_rooms(self) -> None: response = self.make_request( "GET", - "/_synapse/admin/v1/rooms?filter_empty_rooms=false", + "/_synapse/admin/v1/rooms?empty_rooms=false", access_token=self.admin_user_tok, ) self.assertEqual(200, response.code, msg=response.json_body) @@ -1865,7 +1865,7 @@ def test_filter_empty_rooms(self) -> None: response = self.make_request( "GET", - "/_synapse/admin/v1/rooms?filter_empty_rooms=true", + "/_synapse/admin/v1/rooms?empty_rooms=true", access_token=self.admin_user_tok, ) self.assertEqual(200, response.code, msg=response.json_body)