This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Consistently exclude from user_directory, round 2 #10960
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b9638c9
Introduce `should_include_local_users_in_dir`
3f969d1
Introduce register_appservice_user to HomeserverTestCase
76751aa
Check appservice profile changes are ignored
010314d
test population excludes users it should
a8a12a5
Extra assertion in test_initial
8b614d7
Changelog
8c41d2e
Improve docstring of `register_appservice_user`
667ec6e
Use access_token parameter
c8bb561
Assert 200 response!
aeeb697
Add tests which interrogate room sharing tables
c090ab6
Correctly exclude from users_who_share_private_room
3dc823f
`setup` is not a verb
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix a long-standing bug where rebuilding the user directory wouldn't exclude support and disabled users. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,12 +40,10 @@ | |
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
TEMP_TABLE = "_temp_populate_user_directory" | ||
|
||
|
||
class UserDirectoryBackgroundUpdateStore(StateDeltasStore): | ||
|
||
# How many records do we calculate before sending it to | ||
# add_users_who_share_private_rooms? | ||
SHARE_PRIVATE_WORKING_SET = 500 | ||
|
@@ -235,6 +233,13 @@ def _get_next_batch( | |
) | ||
|
||
users_with_profile = await self.get_users_in_room_with_profiles(room_id) | ||
# Throw away users excluded from the directory. | ||
users_with_profile = { | ||
user_id: profile | ||
for user_id, profile in users_with_profile.items() | ||
if not self.hs.is_mine_id(user_id) | ||
or await self.should_include_local_user_in_dir(user_id) | ||
} | ||
|
||
# Update each user in the user directory. | ||
for user_id, profile in users_with_profile.items(): | ||
|
@@ -246,22 +251,19 @@ def _get_next_batch( | |
|
||
if is_public: | ||
for user_id in users_with_profile: | ||
if self.get_if_app_services_interested_in_user(user_id): | ||
continue | ||
|
||
to_insert.add(user_id) | ||
|
||
if to_insert: | ||
await self.add_users_in_public_rooms(room_id, to_insert) | ||
to_insert.clear() | ||
else: | ||
for user_id in users_with_profile: | ||
# We want the set of pairs (L, M) where L and M are | ||
# in `users_with_profile` and L is local. | ||
# Do so by looking for the local user L first. | ||
if not self.hs.is_mine_id(user_id): | ||
continue | ||
|
||
if self.get_if_app_services_interested_in_user(user_id): | ||
continue | ||
|
||
for other_user_id in users_with_profile: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a hard-to-spot oversight right below here on -269. We don't check to see if Instead I'm going to filter out the excluded users early on, right before we assign a value to |
||
if user_id == other_user_id: | ||
continue | ||
|
@@ -349,10 +351,11 @@ def _get_next_batch(txn: LoggingTransaction) -> Optional[List[str]]: | |
) | ||
|
||
for user_id in users_to_work_on: | ||
profile = await self.get_profileinfo(get_localpart_from_id(user_id)) | ||
await self.update_profile_in_user_dir( | ||
user_id, profile.display_name, profile.avatar_url | ||
) | ||
if await self.should_include_local_user_in_dir(user_id): | ||
profile = await self.get_profileinfo(get_localpart_from_id(user_id)) | ||
await self.update_profile_in_user_dir( | ||
user_id, profile.display_name, profile.avatar_url | ||
) | ||
|
||
# We've finished processing a user. Delete it from the table. | ||
await self.db_pool.simple_delete_one( | ||
|
@@ -369,6 +372,24 @@ def _get_next_batch(txn: LoggingTransaction) -> Optional[List[str]]: | |
|
||
return len(users_to_work_on) | ||
|
||
async def should_include_local_user_in_dir(self, user: str) -> bool: | ||
"""Certain classes of local user are omitted from the user directory. | ||
Is this user one of them? | ||
""" | ||
# App service users aren't usually contactable, so exclude them. | ||
if self.get_if_app_services_interested_in_user(user): | ||
# TODO we might want to make this configurable for each app service | ||
return False | ||
|
||
# Support users are for diagnostics and should not appear in the user directory. | ||
if await self.is_support_user(user): | ||
return False | ||
|
||
# Deactivated users aren't contactable, so should not appear in the user directory. | ||
if await self.get_user_deactivated_status(user): | ||
return False | ||
return True | ||
|
||
async def is_room_world_readable_or_publicly_joinable(self, room_id: str) -> bool: | ||
"""Check if the room is either world_readable or publically joinable""" | ||
|
||
|
@@ -537,7 +558,6 @@ async def update_user_directory_stream_pos(self, stream_id: Optional[int]) -> No | |
|
||
|
||
class UserDirectoryStore(UserDirectoryBackgroundUpdateStore): | ||
|
||
# How many records do we calculate before sending it to | ||
# add_users_who_share_private_rooms? | ||
SHARE_PRIVATE_WORKING_SET = 500 | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how these crept in. Possibly I accidentally formatted in pycharm (ctrl-alt-l) and
black
was happy with the change?