-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Directly lookup local membership instead of getting all members in a room first (get_users_in_room
mis-use)
#13608
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactor `get_users_in_room(room_id)` mis-use to lookup single local user with dedicated `check_local_user_in_room(...)` function. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -761,8 +761,10 @@ async def _is_exempt_from_privacy_policy( | |
async def _is_server_notices_room(self, room_id: str) -> bool: | ||
if self.config.servernotices.server_notices_mxid is None: | ||
return False | ||
user_ids = await self.store.get_users_in_room(room_id) | ||
return self.config.servernotices.server_notices_mxid in user_ids | ||
is_server_notices_room = await self.store.check_local_user_in_room( | ||
user_id=self.config.servernotices.server_notices_mxid, room_id=room_id | ||
) | ||
return is_server_notices_room | ||
Comment on lines
761
to
+767
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 are several of these |
||
|
||
async def assert_accepted_privacy_policy(self, requester: Requester) -> None: | ||
"""Check if a user has accepted the privacy policy | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -534,6 +534,32 @@ async def get_local_users_in_room(self, room_id: str) -> List[str]: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
desc="get_local_users_in_room", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def check_local_user_in_room(self, user_id: str, room_id: str) -> bool: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. This is similar to Lines 69 to 119 in a25a370
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check whether a given local user is currently joined to the given room. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A boolean indicating whether the user is currently joined to the room | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Raises: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Exeption when called with a non-local user to this homeserver | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not self.hs.is_mine_id(user_id): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise Exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Cannot call 'check_local_user_in_room' on " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"non-local user %s" % (user_id,), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
membership, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
member_event_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) = await self.get_local_current_membership_for_user_in_room( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
user_id=user_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
room_id=room_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return membership == Membership.JOIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
async def get_local_current_membership_for_user_in_room( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self, user_id: str, room_id: str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) -> Tuple[Optional[str], Optional[str]]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -999,7 +999,7 @@ def assert_annotations(bundled_aggregations: JsonDict) -> None: | |
bundled_aggregations, | ||
) | ||
|
||
self._test_bundled_aggregations(RelationTypes.ANNOTATION, assert_annotations, 6) | ||
self._test_bundled_aggregations(RelationTypes.ANNOTATION, assert_annotations, 7) | ||
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. My guess is the difference between cached calls of |
||
|
||
def test_annotation_to_annotation(self) -> None: | ||
"""Any relation to an annotation should be ignored.""" | ||
|
@@ -1035,7 +1035,7 @@ def assert_annotations(bundled_aggregations: JsonDict) -> None: | |
bundled_aggregations, | ||
) | ||
|
||
self._test_bundled_aggregations(RelationTypes.REFERENCE, assert_annotations, 6) | ||
self._test_bundled_aggregations(RelationTypes.REFERENCE, assert_annotations, 7) | ||
|
||
def test_thread(self) -> None: | ||
""" | ||
|
@@ -1080,21 +1080,21 @@ def assert_thread(bundled_aggregations: JsonDict) -> None: | |
|
||
# The "user" sent the root event and is making queries for the bundled | ||
# aggregations: they have participated. | ||
self._test_bundled_aggregations(RelationTypes.THREAD, _gen_assert(True), 8) | ||
self._test_bundled_aggregations(RelationTypes.THREAD, _gen_assert(True), 9) | ||
# The "user2" sent replies in the thread and is making queries for the | ||
# bundled aggregations: they have participated. | ||
# | ||
# Note that this re-uses some cached values, so the total number of | ||
# queries is much smaller. | ||
self._test_bundled_aggregations( | ||
RelationTypes.THREAD, _gen_assert(True), 2, access_token=self.user2_token | ||
RelationTypes.THREAD, _gen_assert(True), 3, access_token=self.user2_token | ||
) | ||
|
||
# A user with no interactions with the thread: they have not participated. | ||
user3_id, user3_token = self._create_user("charlie") | ||
self.helper.join(self.room, user=user3_id, tok=user3_token) | ||
self._test_bundled_aggregations( | ||
RelationTypes.THREAD, _gen_assert(False), 2, access_token=user3_token | ||
RelationTypes.THREAD, _gen_assert(False), 3, access_token=user3_token | ||
) | ||
|
||
def test_thread_with_bundled_aggregations_for_latest(self) -> None: | ||
|
@@ -1142,7 +1142,7 @@ def assert_thread(bundled_aggregations: JsonDict) -> None: | |
bundled_aggregations["latest_event"].get("unsigned"), | ||
) | ||
|
||
self._test_bundled_aggregations(RelationTypes.THREAD, assert_thread, 8) | ||
self._test_bundled_aggregations(RelationTypes.THREAD, assert_thread, 9) | ||
|
||
def test_nested_thread(self) -> None: | ||
""" | ||
|
Uh oh!
There was an error while loading. Please reload this page.