Add some string constants to topic.py.

The goal here is to make it easy to
forbid "subject" in actions.py.
This commit is contained in:
Steve Howell 2018-11-01 17:26:20 +00:00 committed by Tim Abbott
parent 7252861785
commit 0e854288ee
2 changed files with 16 additions and 4 deletions

View File

@ -58,6 +58,10 @@ from zerver.lib.stream_topic import StreamTopicTarget
from zerver.lib.topic import ( from zerver.lib.topic import (
filter_by_exact_message_topic, filter_by_exact_message_topic,
filter_by_topic_name_via_message, filter_by_topic_name_via_message,
ORIG_TOPIC,
PREV_TOPIC,
TOPIC_LINKS,
TOPIC_NAME,
) )
from zerver.lib.topic_mutes import ( from zerver.lib.topic_mutes import (
get_topic_mutes, get_topic_mutes,
@ -3954,13 +3958,15 @@ def do_update_message(user_profile: UserProfile, message: Message, topic_name: O
if topic_name is not None: if topic_name is not None:
orig_topic_name = message.topic_name() orig_topic_name = message.topic_name()
topic_name = truncate_topic(topic_name) topic_name = truncate_topic(topic_name)
event["orig_subject"] = orig_topic_name
event["propagate_mode"] = propagate_mode event["propagate_mode"] = propagate_mode
message.set_topic_name(topic_name) message.set_topic_name(topic_name)
event["stream_id"] = message.recipient.type_id event["stream_id"] = message.recipient.type_id
event["subject"] = topic_name
event['subject_links'] = bugdown.subject_links(message.sender.realm_id, topic_name) # These fields have legacy field names.
edit_history_event["prev_subject"] = orig_topic_name event[ORIG_TOPIC] = orig_topic_name
event[TOPIC_NAME] = topic_name
event[TOPIC_LINKS] = bugdown.subject_links(message.sender.realm_id, topic_name)
edit_history_event[PREV_TOPIC] = orig_topic_name
if propagate_mode in ["change_later", "change_all"]: if propagate_mode in ["change_later", "change_all"]:
propagate_query = Q(recipient = message.recipient, subject = orig_topic_name) propagate_query = Q(recipient = message.recipient, subject = orig_topic_name)

View File

@ -9,6 +9,12 @@ from zerver.models import (
from typing import Any, Dict, List, Tuple from typing import Any, Dict, List, Tuple
# Only use these constants for events.
ORIG_TOPIC = "orig_subject"
TOPIC_NAME = "subject"
TOPIC_LINKS = "subject_links"
PREV_TOPIC = "prev_subject"
def filter_by_exact_message_topic(query: QuerySet, message: Message) -> QuerySet: def filter_by_exact_message_topic(query: QuerySet, message: Message) -> QuerySet:
topic_name = message.topic_name() topic_name = message.topic_name()
return query.filter(subject=topic_name) return query.filter(subject=topic_name)