Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

bulk_access_messages_expect_usermessage: Fix function name and comments.

Mateusz Manderaf3a304748478
diff --git a/zerver/lib/message.py b/zerver/lib/message.py
index 81aa47c3a76..5e049d290c4 100644
--- a/zerver/lib/message.py
+++ b/zerver/lib/message.py
@@ -901,7 +901,7 @@ def bulk_access_messages(
filtered_messages = []
user_message_set = set(
- bulk_access_messages_expect_usermessage(
+ get_messages_with_usermessage_rows_for_user(
user_profile.id, [message.id for message in messages]
)
)
@@ -934,21 +934,17 @@ def bulk_access_messages(
return filtered_messages
-def bulk_access_messages_expect_usermessage(
+def get_messages_with_usermessage_rows_for_user(
user_profile_id: int, message_ids: Sequence[int]
) -> ValuesQuerySet[UserMessage, int]:
"""
- Like bulk_access_messages, but faster and potentially stricter.
-
Returns a subset of `message_ids` containing only messages the
- user can access. Makes O(1) database queries.
-
- Use this function only when the user is expected to have a
- UserMessage row for every message in `message_ids`. If a
- UserMessage row is missing, the message will be omitted even if
- the user has access (e.g. because it went to a public stream.)
+ user has a UserMessage for. Makes O(1) database queries.
+ Note that this is not sufficient for access verification for
+ stream messages.
- See also: `access_message`, `bulk_access_messages`.
+ See `access_message`, `bulk_access_messages` for proper message access
+ checks that follow our security model.
"""
return UserMessage.objects.filter(
user_profile_id=user_profile_id,
diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py
index 8998162dff1..9ba27ed2132 100644
--- a/zerver/lib/push_notifications.py
+++ b/zerver/lib/push_notifications.py
@@ -1009,8 +1009,8 @@ def handle_remove_push_notification(user_profile_id: int, message_ids: List[int]
# and then (3) it was deleted. When trying to send the push
# notification for (2), after (3) has happened, there is no
# message to fetch -- but we nonetheless want to remove the mobile
- # notification. Because of this, the usual access control of
- # `bulk_access_messages_expect_usermessage` is skipped here.
+ # notification. Because of this, verification of access to
+ # the messages is skipped here.
# Because of this, no access to the Message objects should be
# done; they are treated as a list of opaque ints.