Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Ley
synapse
Commits
37b845da
Unverified
Commit
37b845da
authored
3 years ago
by
David Robertson
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Don't remove local users from dir when the leave their last room (#11103)
parent
e09be0c8
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
changelog.d/11103.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/11103.bugfix
synapse/handlers/user_directory.py
+8
-5
8 additions, 5 deletions
synapse/handlers/user_directory.py
tests/handlers/test_user_directory.py
+50
-0
50 additions, 0 deletions
tests/handlers/test_user_directory.py
with
59 additions
and
5 deletions
changelog.d/11103.bugfix
0 → 100644
+
1
−
0
View file @
37b845da
Fix local users who left all their rooms being removed from the user directory, even if the "search_all_users" config option was enabled.
\ No newline at end of file
This diff is collapsed.
Click to expand it.
synapse/handlers/user_directory.py
+
8
−
5
View file @
37b845da
...
@@ -415,16 +415,19 @@ class UserDirectoryHandler(StateDeltasHandler):
...
@@ -415,16 +415,19 @@ class UserDirectoryHandler(StateDeltasHandler):
room_id: The room ID that user left or stopped being public that
room_id: The room ID that user left or stopped being public that
user_id
user_id
"""
"""
logger
.
debug
(
"
Removing user %r
"
,
user
_id
)
logger
.
debug
(
"
Removing user %r
from room %r
"
,
user_id
,
room
_id
)
# Remove user from sharing tables
# Remove user from sharing tables
await
self
.
store
.
remove_user_who_share_room
(
user_id
,
room_id
)
await
self
.
store
.
remove_user_who_share_room
(
user_id
,
room_id
)
# Are they still in any rooms? If not, remove them entirely.
# Additionally, if they're a remote user and we're no longer joined
rooms_user_is_in
=
await
self
.
store
.
get_user_dir_rooms_user_is_in
(
user_id
)
# to any rooms they're in, remove them from the user directory.
if
not
self
.
is_mine_id
(
user_id
):
rooms_user_is_in
=
await
self
.
store
.
get_user_dir_rooms_user_is_in
(
user_id
)
if
len
(
rooms_user_is_in
)
==
0
:
if
len
(
rooms_user_is_in
)
==
0
:
await
self
.
store
.
remove_from_user_dir
(
user_id
)
logger
.
debug
(
"
Removing user %r from directory
"
,
user_id
)
await
self
.
store
.
remove_from_user_dir
(
user_id
)
async
def
_handle_possible_remote_profile_change
(
async
def
_handle_possible_remote_profile_change
(
self
,
self
,
...
...
This diff is collapsed.
Click to expand it.
tests/handlers/test_user_directory.py
+
50
−
0
View file @
37b845da
...
@@ -914,6 +914,56 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
...
@@ -914,6 +914,56 @@ class UserDirectoryTestCase(unittest.HomeserverTestCase):
self
.
hs
.
get_storage
().
persistence
.
persist_event
(
event
,
context
)
self
.
hs
.
get_storage
().
persistence
.
persist_event
(
event
,
context
)
)
)
def
test_local_user_leaving_room_remains_in_user_directory
(
self
)
->
None
:
"""
We
'
ve chosen to simplify the user directory
'
s implementation by
always including local users. Ensure this invariant is maintained when
a local user
- leaves a room, and
- leaves the last room they
'
re in which is visible to this server.
This is user-visible if the
"
search_all_users
"
config option is on: the
local user who left a room would no longer be searchable if this test fails!
"""
alice
=
self
.
register_user
(
"
alice
"
,
"
pass
"
)
alice_token
=
self
.
login
(
alice
,
"
pass
"
)
bob
=
self
.
register_user
(
"
bob
"
,
"
pass
"
)
bob_token
=
self
.
login
(
bob
,
"
pass
"
)
# Alice makes two public rooms, which Bob joins.
room1
=
self
.
helper
.
create_room_as
(
alice
,
is_public
=
True
,
tok
=
alice_token
)
room2
=
self
.
helper
.
create_room_as
(
alice
,
is_public
=
True
,
tok
=
alice_token
)
self
.
helper
.
join
(
room1
,
bob
,
tok
=
bob_token
)
self
.
helper
.
join
(
room2
,
bob
,
tok
=
bob_token
)
# The user directory tables are updated.
users
,
in_public
,
in_private
=
self
.
get_success
(
self
.
user_dir_helper
.
get_tables
()
)
self
.
assertEqual
(
users
,
{
alice
,
bob
})
self
.
assertEqual
(
in_public
,
{(
alice
,
room1
),
(
alice
,
room2
),
(
bob
,
room1
),
(
bob
,
room2
)}
)
self
.
assertEqual
(
in_private
,
set
())
# Alice leaves one room. She should still be in the directory.
self
.
helper
.
leave
(
room1
,
alice
,
tok
=
alice_token
)
users
,
in_public
,
in_private
=
self
.
get_success
(
self
.
user_dir_helper
.
get_tables
()
)
self
.
assertEqual
(
users
,
{
alice
,
bob
})
self
.
assertEqual
(
in_public
,
{(
alice
,
room2
),
(
bob
,
room1
),
(
bob
,
room2
)})
self
.
assertEqual
(
in_private
,
set
())
# Alice leaves the other. She should still be in the directory.
self
.
helper
.
leave
(
room2
,
alice
,
tok
=
alice_token
)
self
.
wait_for_background_updates
()
users
,
in_public
,
in_private
=
self
.
get_success
(
self
.
user_dir_helper
.
get_tables
()
)
self
.
assertEqual
(
users
,
{
alice
,
bob
})
self
.
assertEqual
(
in_public
,
{(
bob
,
room1
),
(
bob
,
room2
)})
self
.
assertEqual
(
in_private
,
set
())
class
TestUserDirSearchDisabled
(
unittest
.
HomeserverTestCase
):
class
TestUserDirSearchDisabled
(
unittest
.
HomeserverTestCase
):
servlets
=
[
servlets
=
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment