Skip to content

Commit

Permalink
- Query parameter renamed and description adjusted.
Browse files Browse the repository at this point in the history
- catch-block with print-statement removed.
  • Loading branch information
afechler committed Jun 10, 2024
1 parent f09d000 commit c55b638
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
6 changes: 4 additions & 2 deletions docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
28 changes: 13 additions & 15 deletions synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c55b638

Please sign in to comment.