mirror of
https://github.com/zulip/zulip.git
synced 2025-10-27 18:13:58 +00:00
Replace decentralized topic truncation with a single check when sending messages.
(imported from commit 291c999147dd59a9c7e1d9de446293755c17e99d)
This commit is contained in:
@@ -511,8 +511,7 @@ def check_message(sender, client, message_type_name, message_to,
|
|||||||
subject = subject_name.strip()
|
subject = subject_name.strip()
|
||||||
if subject == "":
|
if subject == "":
|
||||||
raise JsonableError("Topic can't be empty")
|
raise JsonableError("Topic can't be empty")
|
||||||
if len(subject) > MAX_SUBJECT_LENGTH:
|
subject = truncate_topic(subject)
|
||||||
raise JsonableError("Topic too long")
|
|
||||||
## FIXME: Commented out temporarily while we figure out what we want
|
## FIXME: Commented out temporarily while we figure out what we want
|
||||||
# if not valid_stream_name(subject):
|
# if not valid_stream_name(subject):
|
||||||
# return json_error("Invalid subject name")
|
# return json_error("Invalid subject name")
|
||||||
@@ -1483,9 +1482,7 @@ def do_update_message(user_profile, message_id, subject, propagate_mode, content
|
|||||||
subject = subject.strip()
|
subject = subject.strip()
|
||||||
if subject == "":
|
if subject == "":
|
||||||
raise JsonableError("Topic can't be empty")
|
raise JsonableError("Topic can't be empty")
|
||||||
|
subject = truncate_topic(subject)
|
||||||
if len(subject) > MAX_SUBJECT_LENGTH:
|
|
||||||
raise JsonableError("Topic too long")
|
|
||||||
event["orig_subject"] = orig_subject
|
event["orig_subject"] = orig_subject
|
||||||
message.subject = subject
|
message.subject = subject
|
||||||
event["subject"] = subject
|
event["subject"] = subject
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from zerver.models import UserProfile, get_client, MAX_SUBJECT_LENGTH, \
|
from zerver.models import UserProfile, get_client, get_user_profile_by_email
|
||||||
get_user_profile_by_email
|
|
||||||
from zerver.lib.actions import check_send_message, convert_html_to_markdown
|
from zerver.lib.actions import check_send_message, convert_html_to_markdown
|
||||||
from zerver.lib.response import json_success, json_error
|
from zerver.lib.response import json_success, json_error
|
||||||
from zerver.decorator import authenticated_api_view, REQ, \
|
from zerver.decorator import authenticated_api_view, REQ, \
|
||||||
@@ -141,8 +140,6 @@ def api_github_landing(request, user_profile, event=REQ,
|
|||||||
# about them
|
# about them
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
subject = elide_subject(subject)
|
|
||||||
|
|
||||||
# customer14.invalid has a stream per GitHub project and wants the topic to
|
# customer14.invalid has a stream per GitHub project and wants the topic to
|
||||||
# always be 'GitHub'.
|
# always be 'GitHub'.
|
||||||
if user_profile.realm.domain == "customer14.invalid":
|
if user_profile.realm.domain == "customer14.invalid":
|
||||||
@@ -196,11 +193,6 @@ def build_message_from_gitlog(user_profile, name, ref, commits, before, after, u
|
|||||||
|
|
||||||
return (subject, content)
|
return (subject, content)
|
||||||
|
|
||||||
def elide_subject(subject):
|
|
||||||
if len(subject) > MAX_SUBJECT_LENGTH:
|
|
||||||
subject = subject[:MAX_SUBJECT_LENGTH - 3].rstrip() + '...'
|
|
||||||
return subject
|
|
||||||
|
|
||||||
def guess_zulip_user_from_jira(jira_username, realm):
|
def guess_zulip_user_from_jira(jira_username, realm):
|
||||||
try:
|
try:
|
||||||
# Try to find a matching user in Zulip
|
# Try to find a matching user in Zulip
|
||||||
@@ -357,8 +349,6 @@ def api_jira_webhook(request, user_profile):
|
|||||||
logging.warning("Got JIRA event type we don't understand: %s" % (event,))
|
logging.warning("Got JIRA event type we don't understand: %s" % (event,))
|
||||||
return json_error("Unknown JIRA event type")
|
return json_error("Unknown JIRA event type")
|
||||||
|
|
||||||
subject = elide_subject(subject)
|
|
||||||
|
|
||||||
check_send_message(user_profile, get_client("JIRA webhook"), "stream",
|
check_send_message(user_profile, get_client("JIRA webhook"), "stream",
|
||||||
[stream], subject, content)
|
[stream], subject, content)
|
||||||
return json_success()
|
return json_success()
|
||||||
@@ -427,8 +417,6 @@ def api_pivotal_webhook(request, user_profile):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return json_error("Failed to extract data from Pivotal XML response")
|
return json_error("Failed to extract data from Pivotal XML response")
|
||||||
|
|
||||||
subject = elide_subject(subject)
|
|
||||||
|
|
||||||
check_send_message(user_profile, get_client("Pivotal webhook"), "stream",
|
check_send_message(user_profile, get_client("Pivotal webhook"), "stream",
|
||||||
[stream], subject, content)
|
[stream], subject, content)
|
||||||
return json_success()
|
return json_success()
|
||||||
@@ -477,8 +465,6 @@ def api_beanstalk_webhook(request, user_profile,
|
|||||||
subject = "svn r%s" % (revision,)
|
subject = "svn r%s" % (revision,)
|
||||||
content = "%s pushed [revision %s](%s):\n\n> %s" % (author, revision, url, short_commit_msg)
|
content = "%s pushed [revision %s](%s):\n\n> %s" % (author, revision, url, short_commit_msg)
|
||||||
|
|
||||||
subject = elide_subject(subject)
|
|
||||||
|
|
||||||
check_send_message(user_profile, get_client("Beanstalk webhook"), "stream",
|
check_send_message(user_profile, get_client("Beanstalk webhook"), "stream",
|
||||||
["commits"], subject, content)
|
["commits"], subject, content)
|
||||||
return json_success()
|
return json_success()
|
||||||
@@ -522,7 +508,6 @@ def api_newrelic_webhook(request, user_profile, alert=REQ(converter=json_to_dict
|
|||||||
else:
|
else:
|
||||||
return json_error("Unknown webhook request")
|
return json_error("Unknown webhook request")
|
||||||
|
|
||||||
subject = elide_subject(subject)
|
|
||||||
check_send_message(user_profile, get_client("NewRelic webhook"), "stream",
|
check_send_message(user_profile, get_client("NewRelic webhook"), "stream",
|
||||||
[stream], subject, content)
|
[stream], subject, content)
|
||||||
return json_success()
|
return json_success()
|
||||||
@@ -550,7 +535,6 @@ def api_bitbucket_webhook(request, user_profile, payload=REQ(converter=json_to_d
|
|||||||
content = build_commit_list_content(commits, branch, None, payload['user'])
|
content = build_commit_list_content(commits, branch, None, payload['user'])
|
||||||
subject += '/%s' % (branch,)
|
subject += '/%s' % (branch,)
|
||||||
|
|
||||||
subject = elide_subject(subject)
|
|
||||||
check_send_message(user_profile, get_client("BitBucket webhook"), "stream",
|
check_send_message(user_profile, get_client("BitBucket webhook"), "stream",
|
||||||
[stream], subject, content)
|
[stream], subject, content)
|
||||||
return json_success()
|
return json_success()
|
||||||
@@ -700,7 +684,7 @@ def api_freshdesk_webhook(request, user_profile, stream=REQ(default='')):
|
|||||||
|
|
||||||
ticket = TicketDict(ticket_data)
|
ticket = TicketDict(ticket_data)
|
||||||
|
|
||||||
subject = elide_subject("#%s: %s" % (ticket.id, ticket.subject))
|
subject = "#%s: %s" % (ticket.id, ticket.subject)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
event_info = parse_freshdesk_event(ticket.triggered_event)
|
event_info = parse_freshdesk_event(ticket.triggered_event)
|
||||||
|
|||||||
@@ -8,15 +8,9 @@ from zerver.lib.actions import internal_send_message
|
|||||||
|
|
||||||
def format_subject(subject):
|
def format_subject(subject):
|
||||||
"""
|
"""
|
||||||
Escape CR and LF characters, and limit length to MAX_SUBJECT_LENGTH.
|
Escape CR and LF characters.
|
||||||
"""
|
"""
|
||||||
from zerver.models import MAX_SUBJECT_LENGTH
|
return subject.replace('\n', '\\n').replace('\r', '\\r')
|
||||||
subject = subject.replace('\n', '\\n').replace('\r', '\\r')
|
|
||||||
|
|
||||||
if len(subject) > MAX_SUBJECT_LENGTH:
|
|
||||||
subject = subject[:MAX_SUBJECT_LENGTH-3].rstrip() + "..."
|
|
||||||
|
|
||||||
return subject
|
|
||||||
|
|
||||||
def user_info_str(report):
|
def user_info_str(report):
|
||||||
if report['user_full_name'] and report['user_email']:
|
if report['user_full_name'] and report['user_email']:
|
||||||
|
|||||||
Reference in New Issue
Block a user