Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
update search by room_id
Browse files Browse the repository at this point in the history
  • Loading branch information
dklimpel committed Nov 1, 2021
1 parent f1e92e6 commit 2ab73a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/admin_api/rooms.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following query parameters are available:
Specifically, rooms are selected if the search term is contained in
- the room's name,
- the local part of the room's canonical alias, or
- the local part of the room's id.
- the complete (local and server part) room's id (case sensitive).

Defaults to no filtering.

Expand Down
7 changes: 4 additions & 3 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,18 +411,19 @@ async def get_rooms_paginate(
reverse_order: whether to reverse the room list
search_term: a string to filter room names,
canonical alias and room ids by
room ids should only match case sensitive and the complete ID
Returns:
A list of room dicts and an integer representing the total number of
rooms that exist given this query
"""
# Filter room names by a string
where_statement = ""
search_pattern = ""
search_pattern = []
if search_term:
where_statement = """
WHERE LOWER(state.name) LIKE ?
OR LOWER(state.canonical_alias) LIKE ?
OR LOWER(state.room_id) LIKE ?
OR state.room_id = ?
"""

# Our postgres db driver converts ? -> %s in SQL strings as that's the
Expand All @@ -433,7 +434,7 @@ async def get_rooms_paginate(
search_pattern = [
"%" + search_term.lower() + "%",
"#%" + search_term.lower() + "%:%",
"!%" + search_term.lower() + "%:%",
search_term,
]

# Set ordering
Expand Down
10 changes: 6 additions & 4 deletions tests/rest/admin/test_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,10 +913,12 @@ def _search_test(
_search_test(None, "bar")
_search_test(None, "", expected_http_code=400)

# Test that whole room name return no result, because of domain
_search_test(None, room_id_1)
# Test search local part of room id
_search_test(room_id_1, room_id_1[1:10])
# Test that the whole room id returns the room
_search_test(room_id_1, room_id_1)
# Test that the search by room_id is case sensitive
_search_test(None, room_id_1.lower())
# Test search part of local part of room id do not match
_search_test(None, room_id_1[1:10])

# Test that whole room alias return no result, because of domain
_search_test(None, "#Room_Alias1:test")
Expand Down

0 comments on commit 2ab73a0

Please sign in to comment.