mirror of
https://github.com/element-hq/synapse
synced 2024-09-29 14:42:42 +00:00
- Query parameter renamed and description adjusted.
- catch-block with print-statement removed.
This commit is contained in:
parent
f09d00020a
commit
c55b638259
4 changed files with 29 additions and 29 deletions
|
@ -36,8 +36,10 @@ The following query parameters are available:
|
||||||
- the room's name,
|
- the room's name,
|
||||||
- the local part of the room's canonical alias, or
|
- the local part of the room's canonical alias, or
|
||||||
- the complete (local and server part) room's id (case sensitive).
|
- the complete (local and server part) room's id (case sensitive).
|
||||||
* `filter_public_rooms` - Flag to filter public and non-public rooms.
|
* `public_rooms` - Optional flag to filter public rooms. If `true`, only public rooms are queried. If `false`, public rooms are excluded from
|
||||||
* `filter_empty_rooms` - Flag to filter empty and non-empty rooms. A room is empty if joined_members is zero.
|
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.
|
Defaults to no filtering.
|
||||||
|
|
||||||
|
|
|
@ -243,24 +243,22 @@ class ListRoomRestServlet(RestServlet):
|
||||||
errcode=Codes.INVALID_PARAM,
|
errcode=Codes.INVALID_PARAM,
|
||||||
)
|
)
|
||||||
|
|
||||||
filter_public_rooms = parse_boolean(request, "filter_public_rooms")
|
public_rooms = parse_boolean(request, "public_rooms")
|
||||||
filter_empty_rooms = parse_boolean(request, "filter_empty_rooms")
|
empty_rooms = parse_boolean(request, "empty_rooms")
|
||||||
|
|
||||||
direction = parse_enum(request, "dir", Direction, default=Direction.FORWARDS)
|
direction = parse_enum(request, "dir", Direction, default=Direction.FORWARDS)
|
||||||
reverse_order = True if direction == Direction.BACKWARDS else False
|
reverse_order = True if direction == Direction.BACKWARDS else False
|
||||||
try:
|
|
||||||
# Return list of rooms according to parameters
|
# Return list of rooms according to parameters
|
||||||
rooms, total_rooms = await self.store.get_rooms_paginate(
|
rooms, total_rooms = await self.store.get_rooms_paginate(
|
||||||
start,
|
start,
|
||||||
limit,
|
limit,
|
||||||
order_by,
|
order_by,
|
||||||
reverse_order,
|
reverse_order,
|
||||||
search_term,
|
search_term,
|
||||||
filter_public_rooms,
|
public_rooms,
|
||||||
filter_empty_rooms,
|
empty_rooms,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
# next_token should be opaque, so return a value the client can parse
|
# next_token should be opaque, so return a value the client can parse
|
||||||
|
|
|
@ -606,8 +606,8 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
|
||||||
order_by: str,
|
order_by: str,
|
||||||
reverse_order: bool,
|
reverse_order: bool,
|
||||||
search_term: Optional[str],
|
search_term: Optional[str],
|
||||||
filter_public_rooms: Optional[bool],
|
public_rooms: Optional[bool],
|
||||||
filter_empty_rooms: Optional[bool],
|
empty_rooms: Optional[bool],
|
||||||
) -> Tuple[List[Dict[str, Any]], int]:
|
) -> Tuple[List[Dict[str, Any]], int]:
|
||||||
"""Function to retrieve a paginated list of rooms as json.
|
"""Function to retrieve a paginated list of rooms as json.
|
||||||
|
|
||||||
|
@ -619,10 +619,10 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
|
||||||
search_term: a string to filter room names,
|
search_term: a string to filter room names,
|
||||||
canonical alias and room ids by.
|
canonical alias and room ids by.
|
||||||
Room ID must match exactly. Canonical alias must match a substring of the local part.
|
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
|
if false, public rooms are excluded from the query. When it is
|
||||||
none (the default), both public rooms and none-public-rooms are queried.
|
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.
|
A room is empty if joined_members is zero.
|
||||||
If true, empty rooms are queried.
|
If true, empty rooms are queried.
|
||||||
if false, empty rooms are excluded from the query. When it is
|
if false, empty rooms are excluded from the query. When it is
|
||||||
|
@ -651,12 +651,12 @@ class RoomWorkerStore(CacheInvalidationWorkerStore):
|
||||||
f"#%{search_term.lower()}%:%",
|
f"#%{search_term.lower()}%:%",
|
||||||
search_term,
|
search_term,
|
||||||
]
|
]
|
||||||
if filter_public_rooms is not None:
|
if public_rooms is not None:
|
||||||
filter_arg = "1" if filter_public_rooms else "0"
|
filter_arg = "1" if public_rooms else "0"
|
||||||
filter_.append(f"rooms.is_public = '{filter_arg}'")
|
filter_.append(f"rooms.is_public = '{filter_arg}'")
|
||||||
|
|
||||||
if filter_empty_rooms is not None:
|
if empty_rooms is not None:
|
||||||
if filter_empty_rooms:
|
if empty_rooms:
|
||||||
filter_.append("curr.joined_members = 0")
|
filter_.append("curr.joined_members = 0")
|
||||||
else:
|
else:
|
||||||
filter_.append("curr.joined_members <> 0")
|
filter_.append("curr.joined_members <> 0")
|
||||||
|
|
|
@ -1817,7 +1817,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
response = self.make_request(
|
response = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/rooms?filter_public_rooms=true",
|
"/_synapse/admin/v1/rooms?public_rooms=true",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, response.code, msg=response.json_body)
|
self.assertEqual(200, response.code, msg=response.json_body)
|
||||||
|
@ -1826,7 +1826,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
response = self.make_request(
|
response = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/rooms?filter_public_rooms=false",
|
"/_synapse/admin/v1/rooms?public_rooms=false",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, response.code, msg=response.json_body)
|
self.assertEqual(200, response.code, msg=response.json_body)
|
||||||
|
@ -1856,7 +1856,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
response = self.make_request(
|
response = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/rooms?filter_empty_rooms=false",
|
"/_synapse/admin/v1/rooms?empty_rooms=false",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, response.code, msg=response.json_body)
|
self.assertEqual(200, response.code, msg=response.json_body)
|
||||||
|
@ -1865,7 +1865,7 @@ class RoomTestCase(unittest.HomeserverTestCase):
|
||||||
|
|
||||||
response = self.make_request(
|
response = self.make_request(
|
||||||
"GET",
|
"GET",
|
||||||
"/_synapse/admin/v1/rooms?filter_empty_rooms=true",
|
"/_synapse/admin/v1/rooms?empty_rooms=true",
|
||||||
access_token=self.admin_user_tok,
|
access_token=self.admin_user_tok,
|
||||||
)
|
)
|
||||||
self.assertEqual(200, response.code, msg=response.json_body)
|
self.assertEqual(200, response.code, msg=response.json_body)
|
||||||
|
|
Loading…
Reference in a new issue