Skip to content

Commit 816f5e1

Browse files
committed
Revert "Add the ability to exclude remote users in user directory search results (element-hq#18300)"
This reverts commit fe8bb62. It introduced a regression in the workers test suite
1 parent fe8bb62 commit 816f5e1

File tree

6 files changed

+4
-84
lines changed

6 files changed

+4
-84
lines changed

changelog.d/18300.feature

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/usage/configuration/config_documentation.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,7 +4095,6 @@ This option has the following sub-options:
40954095
* `prefer_local_users`: Defines whether to prefer local users in search query results.
40964096
If set to true, local users are more likely to appear above remote users when searching the
40974097
user directory. Defaults to false.
4098-
* `exclude_remote_users`: If set to true, the search will only return local users. Defaults to false.
40994098
* `show_locked_users`: Defines whether to show locked users in search query results. Defaults to false.
41004099

41014100
Example configuration:
@@ -4104,7 +4103,6 @@ user_directory:
41044103
enabled: false
41054104
search_all_users: true
41064105
prefer_local_users: true
4107-
exclude_remote_users: false
41084106
show_locked_users: true
41094107
```
41104108
---

synapse/config/user_directory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
3838
self.user_directory_search_all_users = user_directory_config.get(
3939
"search_all_users", False
4040
)
41-
self.user_directory_exclude_remote_users = user_directory_config.get(
42-
"exclude_remote_users", False
43-
)
4441
self.user_directory_search_prefer_local_users = user_directory_config.get(
4542
"prefer_local_users", False
4643
)

synapse/handlers/user_directory.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ def __init__(self, hs: "HomeServer"):
108108
self.is_mine_id = hs.is_mine_id
109109
self.update_user_directory = hs.config.worker.should_update_user_directory
110110
self.search_all_users = hs.config.userdirectory.user_directory_search_all_users
111-
self.exclude_remote_users = (
112-
hs.config.userdirectory.user_directory_exclude_remote_users
113-
)
114111
self.show_locked_users = hs.config.userdirectory.show_locked_users
115112
self._spam_checker_module_callbacks = hs.get_module_api_callbacks().spam_checker
116113
self._hs = hs

synapse/storage/databases/main/user_directory.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,11 +1037,11 @@ async def search_user_dir(
10371037
}
10381038
"""
10391039

1040-
join_args: Tuple[str, ...] = (user_id,)
1041-
10421040
if self.hs.config.userdirectory.user_directory_search_all_users:
1041+
join_args = (user_id,)
10431042
where_clause = "user_id != ?"
10441043
else:
1044+
join_args = (user_id,)
10451045
where_clause = """
10461046
(
10471047
EXISTS (select 1 from users_in_public_rooms WHERE user_id = t.user_id)
@@ -1055,14 +1055,6 @@ async def search_user_dir(
10551055
if not show_locked_users:
10561056
where_clause += " AND (u.locked IS NULL OR u.locked = FALSE)"
10571057

1058-
# Adjust the JOIN type based on the exclude_remote_users flag (the users
1059-
# table only contains local users so an inner join is a good way to
1060-
# to exclude remote users)
1061-
if self.hs.config.userdirectory.user_directory_exclude_remote_users:
1062-
join_type = "JOIN"
1063-
else:
1064-
join_type = "LEFT JOIN"
1065-
10661058
# We allow manipulating the ranking algorithm by injecting statements
10671059
# based on config options.
10681060
additional_ordering_statements = []
@@ -1094,7 +1086,7 @@ async def search_user_dir(
10941086
SELECT d.user_id AS user_id, display_name, avatar_url
10951087
FROM matching_users as t
10961088
INNER JOIN user_directory AS d USING (user_id)
1097-
%(join_type)s users AS u ON t.user_id = u.name
1089+
LEFT JOIN users AS u ON t.user_id = u.name
10981090
WHERE
10991091
%(where_clause)s
11001092
ORDER BY
@@ -1123,7 +1115,6 @@ async def search_user_dir(
11231115
""" % {
11241116
"where_clause": where_clause,
11251117
"order_case_statements": " ".join(additional_ordering_statements),
1126-
"join_type": join_type,
11271118
}
11281119
args = (
11291120
(full_query,)
@@ -1151,7 +1142,7 @@ async def search_user_dir(
11511142
SELECT d.user_id AS user_id, display_name, avatar_url
11521143
FROM user_directory_search as t
11531144
INNER JOIN user_directory AS d USING (user_id)
1154-
%(join_type)s users AS u ON t.user_id = u.name
1145+
LEFT JOIN users AS u ON t.user_id = u.name
11551146
WHERE
11561147
%(where_clause)s
11571148
AND value MATCH ?
@@ -1164,7 +1155,6 @@ async def search_user_dir(
11641155
""" % {
11651156
"where_clause": where_clause,
11661157
"order_statements": " ".join(additional_ordering_statements),
1167-
"join_type": join_type,
11681158
}
11691159
args = join_args + (search_query,) + ordering_arguments + (limit + 1,)
11701160
else:

tests/handlers/test_user_directory.py

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -992,67 +992,6 @@ def test_prefer_local_users(self) -> None:
992992
[self.assertIn(user, local_users) for user in received_user_id_ordering[:3]]
993993
[self.assertIn(user, remote_users) for user in received_user_id_ordering[3:]]
994994

995-
@override_config(
996-
{
997-
"user_directory": {
998-
"enabled": True,
999-
"search_all_users": True,
1000-
"exclude_remote_users": True,
1001-
}
1002-
}
1003-
)
1004-
def test_exclude_remote_users(self) -> None:
1005-
"""Tests that only local users are returned when
1006-
user_directory.exclude_remote_users is True.
1007-
"""
1008-
1009-
# Create a room and few users to test the directory with
1010-
searching_user = self.register_user("searcher", "password")
1011-
searching_user_tok = self.login("searcher", "password")
1012-
1013-
room_id = self.helper.create_room_as(
1014-
searching_user,
1015-
room_version=RoomVersions.V1.identifier,
1016-
tok=searching_user_tok,
1017-
)
1018-
1019-
# Create a few local users and join them to the room
1020-
local_user_1 = self.register_user("user_xxxxx", "password")
1021-
local_user_2 = self.register_user("user_bbbbb", "password")
1022-
local_user_3 = self.register_user("user_zzzzz", "password")
1023-
1024-
self._add_user_to_room(room_id, RoomVersions.V1, local_user_1)
1025-
self._add_user_to_room(room_id, RoomVersions.V1, local_user_2)
1026-
self._add_user_to_room(room_id, RoomVersions.V1, local_user_3)
1027-
1028-
# Create a few "remote" users and join them to the room
1029-
remote_user_1 = "@user_aaaaa:remote_server"
1030-
remote_user_2 = "@user_yyyyy:remote_server"
1031-
remote_user_3 = "@user_ccccc:remote_server"
1032-
self._add_user_to_room(room_id, RoomVersions.V1, remote_user_1)
1033-
self._add_user_to_room(room_id, RoomVersions.V1, remote_user_2)
1034-
self._add_user_to_room(room_id, RoomVersions.V1, remote_user_3)
1035-
1036-
local_users = [local_user_1, local_user_2, local_user_3]
1037-
remote_users = [remote_user_1, remote_user_2, remote_user_3]
1038-
1039-
# The local searching user searches for the term "user", which other users have
1040-
# in their user id
1041-
results = self.get_success(
1042-
self.handler.search_users(searching_user, "user", 20)
1043-
)["results"]
1044-
received_user_ids = [result["user_id"] for result in results]
1045-
1046-
for user in local_users:
1047-
self.assertIn(
1048-
user, received_user_ids, f"Local user {user} not found in results"
1049-
)
1050-
1051-
for user in remote_users:
1052-
self.assertNotIn(
1053-
user, received_user_ids, f"Remote user {user} should not be in results"
1054-
)
1055-
1056995
def _add_user_to_room(
1057996
self,
1058997
room_id: str,

0 commit comments

Comments
 (0)