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.

recipient_users: Move check_sender_can_access_recipients into lib.

Sahil Batra9de2a87ad24e
diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py
index 3cd4439b874..2704d876397 100644
--- a/zerver/actions/message_send.py
+++ b/zerver/actions/message_send.py
@@ -61,7 +61,10 @@ from zerver.lib.notification_data import (
)
from zerver.lib.query_helpers import query_for_ids
from zerver.lib.queue import queue_event_on_commit
-from zerver.lib.recipient_users import recipient_for_user_profiles
+from zerver.lib.recipient_users import (
+ check_sender_can_access_recipients,
+ recipient_for_user_profiles,
+)
from zerver.lib.stream_subscription import (
get_subscriptions_for_send_message,
num_subscribers_for_stream_id,
@@ -96,7 +99,6 @@ from zerver.lib.users import (
get_subscribers_of_target_user_subscriptions,
get_user_ids_who_can_access_user,
get_users_involved_in_dms_with_target_users,
- has_inaccessible_users,
user_access_restricted_in_realm,
)
from zerver.lib.validator import check_widget_content
@@ -1684,14 +1686,6 @@ def check_can_send_direct_message(
raise DirectMessageInitiationError
-def check_sender_can_access_recipients(
- sender: UserProfile, user_profiles: Sequence[UserProfile]
-) -> None:
- recipient_user_ids = [user.id for user in user_profiles]
- if has_inaccessible_users(recipient_user_ids, sender):
- raise JsonableError(_("You do not have permission to access some of the recipients."))
-
-
def get_recipients_for_user_creation_events(
realm: Realm, sender: UserProfile, user_profiles: Sequence[UserProfile]
) -> dict[UserProfile, set[int]]:
diff --git a/zerver/lib/recipient_users.py b/zerver/lib/recipient_users.py
index a4522f276fe..6b20c5c733e 100644
--- a/zerver/lib/recipient_users.py
+++ b/zerver/lib/recipient_users.py
@@ -3,6 +3,8 @@ from collections.abc import Sequence
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
+from zerver.lib.exceptions import JsonableError
+from zerver.lib.users import has_inaccessible_users
from zerver.models import DirectMessageGroup, Recipient, UserProfile
from zerver.models.recipients import (
get_direct_message_group_hash,
@@ -100,3 +102,11 @@ def recipient_for_user_profiles(
return get_recipient_from_user_profiles(
recipient_profiles, forwarded_mirror_message, forwarder_user_profile, sender, create=create
)
+
+
+def check_sender_can_access_recipients(
+ sender: UserProfile, user_profiles: Sequence[UserProfile]
+) -> None:
+ recipient_user_ids = [user.id for user in user_profiles]
+ if has_inaccessible_users(recipient_user_ids, sender):
+ raise JsonableError(_("You do not have permission to access some of the recipients."))