mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 09:27:43 +00:00
Rename constant to MAX_TOPIC_NAME_LENGTH.
This commit is contained in:
@@ -84,7 +84,7 @@ from zerver.models import Realm, RealmEmoji, Stream, UserProfile, UserActivity,
|
|||||||
Subscription, Recipient, Message, Attachment, UserMessage, RealmAuditLog, \
|
Subscription, Recipient, Message, Attachment, UserMessage, RealmAuditLog, \
|
||||||
UserHotspot, MultiuseInvite, ScheduledMessage, \
|
UserHotspot, MultiuseInvite, ScheduledMessage, \
|
||||||
Client, DefaultStream, DefaultStreamGroup, UserPresence, PushDeviceToken, \
|
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, \
|
MAX_MESSAGE_LENGTH, get_client, get_stream, get_personal_recipient, get_huddle, \
|
||||||
get_user_profile_by_id, PreregistrationUser, get_display_recipient, \
|
get_user_profile_by_id, PreregistrationUser, get_display_recipient, \
|
||||||
get_realm, bulk_get_recipients, get_stream_recipient, get_stream_recipients, \
|
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, "...")
|
return truncate_content(body, MAX_MESSAGE_LENGTH, "...")
|
||||||
|
|
||||||
def truncate_topic(topic: str) -> str:
|
def truncate_topic(topic: str) -> str:
|
||||||
return truncate_content(topic, MAX_SUBJECT_LENGTH, "...")
|
return truncate_content(topic, MAX_TOPIC_NAME_LENGTH, "...")
|
||||||
|
|
||||||
MessageUpdateUserInfoResult = TypedDict('MessageUpdateUserInfoResult', {
|
MessageUpdateUserInfoResult = TypedDict('MessageUpdateUserInfoResult', {
|
||||||
'message_user_ids': Set[int],
|
'message_user_ids': Set[int],
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from zerver.lib.str_utils import force_text
|
|||||||
from zerver.lib.send_email import FromAddress
|
from zerver.lib.send_email import FromAddress
|
||||||
from zerver.models import Stream, Recipient, \
|
from zerver.models import Stream, Recipient, \
|
||||||
get_user_profile_by_id, get_display_recipient, get_personal_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
|
MAX_MESSAGE_LENGTH
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -192,7 +192,7 @@ def send_zulip(sender: str, stream: Stream, topic: str, content: str) -> None:
|
|||||||
sender,
|
sender,
|
||||||
"stream",
|
"stream",
|
||||||
stream.name,
|
stream.name,
|
||||||
topic[:MAX_SUBJECT_LENGTH],
|
topic[:MAX_TOPIC_NAME_LENGTH],
|
||||||
content[:MAX_MESSAGE_LENGTH],
|
content[:MAX_MESSAGE_LENGTH],
|
||||||
email_gateway=True)
|
email_gateway=True)
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ import time
|
|||||||
import datetime
|
import datetime
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
MAX_SUBJECT_LENGTH = 60
|
MAX_TOPIC_NAME_LENGTH = 60
|
||||||
MAX_MESSAGE_LENGTH = 10000
|
MAX_MESSAGE_LENGTH = 10000
|
||||||
MAX_LANGUAGE_ID_LENGTH = 50 # type: int
|
MAX_LANGUAGE_ID_LENGTH = 50 # type: int
|
||||||
|
|
||||||
@@ -1163,7 +1163,7 @@ class MutedTopic(models.Model):
|
|||||||
user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE)
|
user_profile = models.ForeignKey(UserProfile, on_delete=CASCADE)
|
||||||
stream = models.ForeignKey(Stream, on_delete=CASCADE)
|
stream = models.ForeignKey(Stream, on_delete=CASCADE)
|
||||||
recipient = models.ForeignKey(Recipient, 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:
|
class Meta:
|
||||||
unique_together = ('user_profile', 'stream', 'topic_name')
|
unique_together = ('user_profile', 'stream', 'topic_name')
|
||||||
@@ -1310,7 +1310,7 @@ class AbstractMessage(models.Model):
|
|||||||
# new code should generally also say "topic".
|
# new code should generally also say "topic".
|
||||||
#
|
#
|
||||||
# See also the `topic_name` method on `Message`.
|
# 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
|
content = models.TextField() # type: str
|
||||||
rendered_content = models.TextField(null=True) # type: Optional[str]
|
rendered_content = models.TextField(null=True) # type: Optional[str]
|
||||||
@@ -2161,7 +2161,7 @@ class ScheduledEmail(AbstractScheduledJob):
|
|||||||
class ScheduledMessage(models.Model):
|
class ScheduledMessage(models.Model):
|
||||||
sender = models.ForeignKey(UserProfile, on_delete=CASCADE) # type: UserProfile
|
sender = models.ForeignKey(UserProfile, on_delete=CASCADE) # type: UserProfile
|
||||||
recipient = models.ForeignKey(Recipient, on_delete=CASCADE) # type: Recipient
|
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
|
content = models.TextField() # type: str
|
||||||
sending_client = models.ForeignKey(Client, on_delete=CASCADE) # type: Client
|
sending_client = models.ForeignKey(Client, on_delete=CASCADE) # type: Client
|
||||||
stream = models.ForeignKey(Stream, null=True, on_delete=CASCADE) # type: Optional[Stream]
|
stream = models.ForeignKey(Stream, null=True, on_delete=CASCADE) # type: Optional[Stream]
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ from zerver.lib.soft_deactivation import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from zerver.models 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,
|
Message, Realm, Recipient, Stream, UserMessage, UserProfile, Attachment,
|
||||||
RealmAuditLog, RealmDomain, get_realm, UserPresence, Subscription,
|
RealmAuditLog, RealmDomain, get_realm, UserPresence, Subscription,
|
||||||
get_stream, get_stream_recipient, get_system_bot, get_user, Reaction,
|
get_stream, get_stream_recipient, get_system_bot, get_user, Reaction,
|
||||||
@@ -1546,7 +1546,7 @@ class MessagePOSTTest(ZulipTestCase):
|
|||||||
succeeds, but the topic is truncated.
|
succeeds, but the topic is truncated.
|
||||||
"""
|
"""
|
||||||
self.login(self.example_email("hamlet"))
|
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",
|
post_data = {"type": "stream", "to": "Verona", "client": "test suite",
|
||||||
"content": "test content", "subject": long_topic}
|
"content": "test content", "subject": long_topic}
|
||||||
result = self.client_post("/json/messages", post_data)
|
result = self.client_post("/json/messages", post_data)
|
||||||
@@ -1554,7 +1554,7 @@ class MessagePOSTTest(ZulipTestCase):
|
|||||||
|
|
||||||
sent_message = self.get_last_message()
|
sent_message = self.get_last_message()
|
||||||
self.assertEqual(sent_message.topic_name(),
|
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:
|
def test_send_forged_message_as_not_superuser(self) -> None:
|
||||||
self.login(self.example_email("hamlet"))
|
self.login(self.example_email("hamlet"))
|
||||||
|
|||||||
@@ -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.response import json_error, json_success
|
||||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||||
from zerver.lib.validator import check_dict, check_string
|
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')
|
@api_key_only_webhook_view('Splunk')
|
||||||
@has_request_variables
|
@has_request_variables
|
||||||
@@ -24,8 +24,8 @@ def api_splunk_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||||||
raw = payload.get('result', {}).get('_raw', 'Missing _raw')
|
raw = payload.get('result', {}).get('_raw', 'Missing _raw')
|
||||||
|
|
||||||
# for the default topic, use search name but truncate if too long
|
# for the default topic, use search name but truncate if too long
|
||||||
if len(search_name) >= MAX_SUBJECT_LENGTH:
|
if len(search_name) >= MAX_TOPIC_NAME_LENGTH:
|
||||||
topic = "{}...".format(search_name[:(MAX_SUBJECT_LENGTH - 3)])
|
topic = "{}...".format(search_name[:(MAX_TOPIC_NAME_LENGTH - 3)])
|
||||||
else:
|
else:
|
||||||
topic = search_name
|
topic = search_name
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user