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

Commit

Permalink
Cherry-pick "Fix reactivated users not being added to directory "
Browse files Browse the repository at this point in the history
There was a merge conflict relating to the guard on
user_directory_search_all_users. I've chosen to not reinstate the guard
because:

- it's rare that users are going to be reactivated
- I'm going to remove these guards which stop us from inserting into the directory
in upcoming changes (so that guards just protect the search)
- It's less churn

Was originally:
commit c0b8d1b
Author: David Robertson <davidr@element.io>
Date:   Sat Sep 4 03:22:23 2021 +0100
  • Loading branch information
David Robertson committed Sep 8, 2021
1 parent 66d72b7 commit ad6eab0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
8 changes: 3 additions & 5 deletions synapse/handlers/deactivate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,12 @@ async def activate_account(self, user_id: str) -> None:
"""
# Add the user to the directory, if necessary.
user = UserID.from_string(user_id)
if self.hs.config.user_directory_search_all_users:
profile = await self.store.get_profileinfo(user.localpart)
await self.user_directory_handler.handle_local_profile_change(
user_id, profile
)

# Ensure the user is not marked as erased.
await self.store.mark_user_not_erased(user_id)

# Mark the user as active.
await self.store.set_user_deactivated_status(user_id, False)

profile = await self.store.get_profileinfo(user.localpart)
await self.user_directory_handler.handle_local_profile_change(user_id, profile)
42 changes: 42 additions & 0 deletions tests/handlers/test_user_directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,48 @@ def test_handle_user_deactivated_regular_user(self):
self.get_success(self.handler.handle_user_deactivated(r_user_id))
self.store.remove_from_user_dir.called_once_with(r_user_id)

def test_reactivation_makes_regular_user_searchable(self):
user = self.register_user("regular", "pass")
password_hash = self.get_success(self.store.db_pool.simple_select_one_onecol(
"users",
{"name": user},
"password_hash",
))
user_token = self.login(user, "pass")
admin_user = self.register_user("admin", "pass", admin=True)

# Ensure the regular user is publicly visible and searchable.
self.helper.create_room_as(user, is_public=True, tok=user_token)
s = self.get_success(self.handler.search_users(admin_user, user, 10))
self.assertEqual(len(s["results"]), 1)
self.assertEqual(s["results"][0]["user_id"], user)

# Deactivate the user and check they're not searchable.
deactivate_handler = self.hs._deactivate_account_handler
self.get_success(
deactivate_handler.deactivate_account(
user, erase_data=False, requester=create_requester(admin_user)
)
)
s = self.get_success(self.handler.search_users(admin_user, user, 10))
self.assertEqual(s["results"], [])

# Reactivate the user
self.get_success(deactivate_handler.activate_account(user))
# Hackily reset password by restoring the old pw hash.
self.get_success(self.store.db_pool.simple_update_one(
"users",
{"name": user},
{"password_hash": password_hash},
))
user_token = self.login(user, "pass")
self.helper.create_room_as(user, is_public=True, tok=user_token)

# Check they're searchable.
s = self.get_success(self.handler.search_users(admin_user, user, 10))
self.assertEqual(len(s["results"]), 1)
self.assertEqual(s["results"][0]["user_id"], user)

def test_private_room(self):
"""
A user can be searched for only by people that are either in a public
Expand Down

0 comments on commit ad6eab0

Please sign in to comment.