mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 11:52:01 +00:00
Extract topic_match_sa() helper.
We'll also use this in zerver/views/messages.py, but that's a bigger change.
This commit is contained in:
@@ -276,7 +276,9 @@ def build_custom_checkers(by_lang):
|
||||
'description': 'avoid subject as a var',
|
||||
'good_lines': ['topic_name'],
|
||||
'bad_lines': ['subject="foo"', ' MAX_SUBJECT_LEN'],
|
||||
'include_only': set(['zerver/lib/actions.py'])},
|
||||
'include_only': set([
|
||||
'zerver/lib/actions.py',
|
||||
'zerver/lib/topic_mutes.py'])},
|
||||
{'pattern': '^(?!#)@login_required',
|
||||
'description': '@login_required is unsupported; use @zulip_login_required',
|
||||
'good_lines': ['@zulip_login_required', '# foo @login_required'],
|
||||
|
||||
@@ -4,6 +4,11 @@ from django.db import connection
|
||||
from django.db.models.query import QuerySet, Q
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from sqlalchemy.sql import (
|
||||
column,
|
||||
func,
|
||||
)
|
||||
|
||||
from zerver.models import (
|
||||
Message,
|
||||
Recipient,
|
||||
@@ -18,6 +23,12 @@ TOPIC_NAME = "subject"
|
||||
TOPIC_LINKS = "subject_links"
|
||||
PREV_TOPIC = "prev_subject"
|
||||
|
||||
def topic_match_sa(topic_name: str) -> Any:
|
||||
# _sa is short for Sql Alchemy, which we use mostly for
|
||||
# queries that search messages
|
||||
topic_cond = func.upper(column("subject")) == func.upper(topic_name)
|
||||
return topic_cond
|
||||
|
||||
def filter_by_exact_message_topic(query: QuerySet, message: Message) -> QuerySet:
|
||||
topic_name = message.topic_name()
|
||||
return query.filter(subject=topic_name)
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
from zerver.lib.topic import (
|
||||
topic_match_sa,
|
||||
)
|
||||
from zerver.models import (
|
||||
get_stream_recipient,
|
||||
get_stream,
|
||||
@@ -9,7 +12,6 @@ from zerver.models import (
|
||||
from sqlalchemy.sql import (
|
||||
and_,
|
||||
column,
|
||||
func,
|
||||
not_,
|
||||
or_,
|
||||
Selectable
|
||||
@@ -97,7 +99,7 @@ def exclude_topic_mutes(conditions: List[Selectable],
|
||||
recipient_id = row['recipient_id']
|
||||
topic_name = row['topic_name']
|
||||
stream_cond = column("recipient_id") == recipient_id
|
||||
topic_cond = func.upper(column("subject")) == func.upper(topic_name)
|
||||
topic_cond = topic_match_sa(topic_name)
|
||||
return and_(stream_cond, topic_cond)
|
||||
|
||||
condition = not_(or_(*list(map(mute_cond, rows))))
|
||||
|
||||
Reference in New Issue
Block a user