mirror of https://github.com/zulip/zulip.git
refactor: Extract get_linkable_streams.
This is a one-liner with two purposes: * We want the comment to explain the business rule. * We want to just work in id space.
This commit is contained in:
parent
c4bd4496dd
commit
0359c083d1
|
@ -5,7 +5,7 @@ from typing import Dict, List, Match, Optional, Set, Tuple
|
|||
|
||||
from django.db.models import Q
|
||||
|
||||
from zerver.models import Realm, UserGroup, UserProfile, get_active_streams
|
||||
from zerver.models import Realm, UserGroup, UserProfile, get_linkable_streams
|
||||
|
||||
# Match multi-word string between @** ** or match any one-word
|
||||
# sequences after @
|
||||
|
@ -206,8 +206,8 @@ def get_stream_name_map(realm: Realm, stream_names: Set[str]) -> Dict[str, int]:
|
|||
q_list = {Q(name=name) for name in stream_names}
|
||||
|
||||
rows = (
|
||||
get_active_streams(
|
||||
realm=realm,
|
||||
get_linkable_streams(
|
||||
realm_id=realm.id,
|
||||
)
|
||||
.filter(
|
||||
functools.reduce(lambda a, b: a | b, q_list),
|
||||
|
|
|
@ -2476,6 +2476,16 @@ def get_active_streams(realm: Optional[Realm]) -> QuerySet:
|
|||
return Stream.objects.filter(realm=realm, deactivated=False)
|
||||
|
||||
|
||||
def get_linkable_streams(realm_id: int) -> QuerySet:
|
||||
"""
|
||||
This returns the streams that we are allowed to linkify using
|
||||
something like "#frontend" in our markup. For now the business
|
||||
rule is that you can link any stream in the realm that hasn't
|
||||
been deactivated (similar to how get_active_streams works).
|
||||
"""
|
||||
return Stream.objects.filter(realm_id=realm_id, deactivated=False)
|
||||
|
||||
|
||||
def get_stream(stream_name: str, realm: Realm) -> Stream:
|
||||
"""
|
||||
Callers that don't have a Realm object already available should use
|
||||
|
|
Loading…
Reference in New Issue