mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
message: Reorder checks in has_message_access.
This refactor makes this function easier to read and understand.
This commit is contained in:
@@ -679,7 +679,10 @@ def access_message(
|
|||||||
def has_message_access(
|
def has_message_access(
|
||||||
user_profile: UserProfile, message: Message, user_message: Optional[UserMessage]
|
user_profile: UserProfile, message: Message, user_message: Optional[UserMessage]
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if user_message is None:
|
# If you have a user_message object, you have access.
|
||||||
|
if user_message is not None:
|
||||||
|
return True
|
||||||
|
|
||||||
if message.recipient.type != Recipient.STREAM:
|
if message.recipient.type != Recipient.STREAM:
|
||||||
# You can't access private messages you didn't receive
|
# You can't access private messages you didn't receive
|
||||||
return False
|
return False
|
||||||
@@ -694,29 +697,14 @@ def has_message_access(
|
|||||||
# unless history is public to subscribers.
|
# unless history is public to subscribers.
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not stream.is_public():
|
if stream.is_public() and user_profile.can_access_public_streams():
|
||||||
# This stream is an invite-only stream where message
|
|
||||||
# history is available to subscribers. So we check if
|
|
||||||
# you're subscribed.
|
|
||||||
if not Subscription.objects.filter(
|
|
||||||
user_profile=user_profile, active=True, recipient=message.recipient
|
|
||||||
).exists():
|
|
||||||
return False
|
|
||||||
|
|
||||||
# You are subscribed, so let this fall through to the public stream case.
|
|
||||||
elif user_profile.is_guest:
|
|
||||||
# Guest users don't get automatic access to public stream messages
|
|
||||||
if not Subscription.objects.filter(
|
|
||||||
user_profile=user_profile, active=True, recipient=message.recipient
|
|
||||||
).exists():
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
# Otherwise, the message was sent to a public stream in
|
|
||||||
# your realm, so return the message, user_message pair
|
|
||||||
pass
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# is_history_public_to_subscribers, so check if you're subscribed
|
||||||
|
return Subscription.objects.filter(
|
||||||
|
user_profile=user_profile, active=True, recipient=message.recipient
|
||||||
|
).exists()
|
||||||
|
|
||||||
|
|
||||||
def bulk_access_messages(user_profile: UserProfile, messages: Sequence[Message]) -> List[Message]:
|
def bulk_access_messages(user_profile: UserProfile, messages: Sequence[Message]) -> List[Message]:
|
||||||
filtered_messages = []
|
filtered_messages = []
|
||||||
|
|||||||
Reference in New Issue
Block a user