Rename constant to MAX_TOPIC_NAME_LENGTH.

This commit is contained in:
Steve Howell
2018-11-01 20:23:48 +00:00
committed by Tim Abbott
parent 2cf46f0122
commit af1acf9239
5 changed files with 14 additions and 14 deletions

View File

@@ -84,7 +84,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity,
Subscription, Recipient, Message, Attachment, UserMessage, RealmAuditLog, \
UserHotspot, MultiuseInvite, ScheduledMessage, \
Client, DefaultStream, DefaultStreamGroup, UserPresence, PushDeviceToken, \
ScheduledEmail, MAX_SUBJECT_LENGTH, \
ScheduledEmail, MAX_TOPIC_NAME_LENGTH, \
MAX_MESSAGE_LENGTH, get_client, get_stream, get_personal_recipient, get_huddle, \
get_user_profile_by_id, PreregistrationUser, get_display_recipient, \
get_realm, bulk_get_recipients, get_stream_recipient, get_stream_recipients, \
@@ -3766,7 +3766,7 @@ def truncate_body(body: str) -> str:
return truncate_content(body, MAX_MESSAGE_LENGTH, "...")
def truncate_topic(topic: str) -> str:
return truncate_content(topic, MAX_SUBJECT_LENGTH, "...")
return truncate_content(topic, MAX_TOPIC_NAME_LENGTH, "...")
MessageUpdateUserInfoResult = TypedDict('MessageUpdateUserInfoResult', {
'message_user_ids': Set[int],

View File

@@ -20,7 +20,7 @@ from zerver.lib.str_utils import force_text
from zerver.lib.send_email import FromAddress
from zerver.models import Stream, Recipient, \
get_user_profile_by_id, get_display_recipient, get_personal_recipient, \
Message, Realm, UserProfile, get_system_bot, get_user, MAX_SUBJECT_LENGTH, \
Message, Realm, UserProfile, get_system_bot, get_user, MAX_TOPIC_NAME_LENGTH, \
MAX_MESSAGE_LENGTH
logger = logging.getLogger(__name__)
@@ -192,7 +192,7 @@ def send_zulip(sender: str, stream: Stream, topic: str, content: str) -> None:
sender,
"stream",
stream.name,
topic[:MAX_SUBJECT_LENGTH],
topic[:MAX_TOPIC_NAME_LENGTH],
content[:MAX_MESSAGE_LENGTH],
email_gateway=True)

View File

@@ -53,7 +53,7 @@ import time
import datetime
import sys
MAX_SUBJECT_LENGTH = 60
MAX_TOPIC_NAME_LENGTH = 60
MAX_MESSAGE_LENGTH = 10000
MAX_LANGUAGE_ID_LENGTH = 50 # type: int
@@ -1163,7 +1163,7 @@ class MutedTopic(models.Model):
user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE)
stream = models.ForeignKey(Stream, on_delete=CASCADE)
recipient = models.ForeignKey(Recipient, on_delete=CASCADE)
topic_name = models.CharField(max_length=MAX_SUBJECT_LENGTH)
topic_name = models.CharField(max_length=MAX_TOPIC_NAME_LENGTH)
class Meta:
unique_together = ('user_profile', 'stream', 'topic_name')
@@ -1310,7 +1310,7 @@ class AbstractMessage(models.Model):
# new code should generally also say "topic".
#
# See also the `topic_name` method on `Message`.
subject = models.CharField(max_length=MAX_SUBJECT_LENGTH, db_index=True) # type: str
subject = models.CharField(max_length=MAX_TOPIC_NAME_LENGTH, db_index=True) # type: str
content = models.TextField() # type: str
rendered_content = models.TextField(null=True) # type: Optional[str]
@@ -2161,7 +2161,7 @@ class ScheduledEmail(AbstractScheduledJob):
class ScheduledMessage(models.Model):
sender = models.ForeignKey(UserProfile, on_delete=CASCADE) # type: UserProfile
recipient = models.ForeignKey(Recipient, on_delete=CASCADE) # type: Recipient
subject = models.CharField(max_length=MAX_SUBJECT_LENGTH) # type: str
subject = models.CharField(max_length=MAX_TOPIC_NAME_LENGTH) # type: str
content = models.TextField() # type: str
sending_client = models.ForeignKey(Client, on_delete=CASCADE) # type: Client
stream = models.ForeignKey(Stream, null=True, on_delete=CASCADE) # type: Optional[Stream]

View File

@@ -76,7 +76,7 @@ from zerver.lib.soft_deactivation import (
)
from zerver.models import (
MAX_MESSAGE_LENGTH, MAX_SUBJECT_LENGTH,
MAX_MESSAGE_LENGTH, MAX_TOPIC_NAME_LENGTH,
Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment,
RealmAuditLog, RealmDomain, get_realm, UserPresence, Subscription,
get_stream, get_stream_recipient, get_system_bot, get_user, Reaction,
@@ -1546,7 +1546,7 @@ class MessagePOSTTest(ZulipTestCase):
succeeds, but the topic is truncated.
"""
self.login(self.example_email("hamlet"))
long_topic = "A" * (MAX_SUBJECT_LENGTH + 1)
long_topic = "A" * (MAX_TOPIC_NAME_LENGTH + 1)
post_data = {"type": "stream", "to": "Verona", "client": "test suite",
"content": "test content", "subject": long_topic}
result = self.client_post("/json/messages", post_data)
@@ -1554,7 +1554,7 @@ class MessagePOSTTest(ZulipTestCase):
sent_message = self.get_last_message()
self.assertEqual(sent_message.topic_name(),
"A" * (MAX_SUBJECT_LENGTH - 3) + "...")
"A" * (MAX_TOPIC_NAME_LENGTH - 3) + "...")
def test_send_forged_message_as_not_superuser(self) -> None:
self.login(self.example_email("hamlet"))

View File

@@ -9,7 +9,7 @@ from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_error, json_success
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.lib.validator import check_dict, check_string
from zerver.models import MAX_SUBJECT_LENGTH, UserProfile
from zerver.models import MAX_TOPIC_NAME_LENGTH, UserProfile
@api_key_only_webhook_view('Splunk')
@has_request_variables
@@ -24,8 +24,8 @@ def api_splunk_webhook(request: HttpRequest, user_profile: UserProfile,
raw = payload.get('result', {}).get('_raw', 'Missing _raw')
# for the default topic, use search name but truncate if too long
if len(search_name) >= MAX_SUBJECT_LENGTH:
topic = "{}...".format(search_name[:(MAX_SUBJECT_LENGTH - 3)])
if len(search_name) >= MAX_TOPIC_NAME_LENGTH:
topic = "{}...".format(search_name[:(MAX_TOPIC_NAME_LENGTH - 3)])
else:
topic = search_name