mirror of https://github.com/zulip/zulip.git
messages: Pass UserProfile to is_public_stream_by_name and rename.
The new name can_access_stream_history_by_name gets to the point of what this function actually does. And passing in a user object lets us define what this does based on the user subscribed.
This commit is contained in:
parent
5e82d750c5
commit
228f41e916
|
@ -127,10 +127,12 @@ def access_stream_for_unmute_topic(user_profile: UserProfile, stream_name: Text,
|
|||
raise JsonableError(error)
|
||||
return stream
|
||||
|
||||
def is_public_stream_by_name(stream_name: Text, realm: Realm) -> bool:
|
||||
"""Determine whether a stream is public, so that
|
||||
our caller can decide whether we can get
|
||||
historical messages for a narrowing search.
|
||||
def can_access_stream_history_by_name(user_profile: UserProfile, stream_name: Text) -> bool:
|
||||
"""Determine whether the provided user is allowed to access the
|
||||
history of the target stream. The stream is specified by name.
|
||||
|
||||
This is used by the caller to determine whether this user can get
|
||||
historical messages before they joined for a narrowing search.
|
||||
|
||||
Because of the way our search is currently structured,
|
||||
we may be passed an invalid stream here. We return
|
||||
|
@ -142,7 +144,7 @@ def is_public_stream_by_name(stream_name: Text, realm: Realm) -> bool:
|
|||
can actually see this stream.
|
||||
"""
|
||||
try:
|
||||
stream = get_stream(stream_name, realm)
|
||||
stream = get_stream(stream_name, user_profile.realm)
|
||||
except Stream.DoesNotExist:
|
||||
return False
|
||||
return stream.is_public()
|
||||
|
|
|
@ -29,7 +29,7 @@ from zerver.lib.message import (
|
|||
)
|
||||
from zerver.lib.response import json_success, json_error
|
||||
from zerver.lib.sqlalchemy_utils import get_sqlalchemy_connection
|
||||
from zerver.lib.streams import access_stream_by_id, is_public_stream_by_name
|
||||
from zerver.lib.streams import access_stream_by_id, can_access_stream_history_by_name
|
||||
from zerver.lib.timestamp import datetime_to_timestamp, convert_to_UTC
|
||||
from zerver.lib.timezone import get_timezone
|
||||
from zerver.lib.topic_mutes import exclude_topic_mutes
|
||||
|
@ -506,7 +506,7 @@ def ok_to_include_history(narrow: Optional[Iterable[Dict[str, Any]]], user_profi
|
|||
if narrow is not None:
|
||||
for term in narrow:
|
||||
if term['operator'] == "stream" and not term.get('negated', False):
|
||||
if is_public_stream_by_name(term['operand'], user_profile.realm):
|
||||
if can_access_stream_history_by_name(user_profile, term['operand']):
|
||||
include_history = True
|
||||
# Disable historical messages if the user is narrowing on anything
|
||||
# that's a property on the UserMessage table. There cannot be
|
||||
|
|
Loading…
Reference in New Issue