From e1c1f96f9e0411f29aff5bf7897b0b9d44000f6b Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sun, 5 Mar 2017 23:40:34 -0800 Subject: [PATCH] zilencer: Eliminate submit_feedback indirection. --- zerver/lib/feedback.py | 7 ++++--- zerver/worker/queue_processors.py | 3 +++ zilencer/urls.py | 2 -- zilencer/views.py | 7 ------- zproject/settings.py | 1 + 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/zerver/lib/feedback.py b/zerver/lib/feedback.py index 67a7d84630..9dd6d05a71 100644 --- a/zerver/lib/feedback.py +++ b/zerver/lib/feedback.py @@ -1,6 +1,7 @@ from __future__ import absolute_import -from typing import Any, Dict, Optional, Text +from django.conf import settings +from typing import Any, Mapping, Optional, Text from zerver.lib.actions import internal_send_message from zerver.lib.redis_utils import get_redis_client @@ -44,7 +45,7 @@ def get_ticket_number(): return ticket_number def deliver_feedback_by_zulip(message): - # type: (Dict[str, Any]) -> None + # type: (Mapping[str, Any]) -> None subject = "%s" % (message["sender_email"],) if len(subject) > 60: @@ -72,4 +73,4 @@ def deliver_feedback_by_zulip(message): content += message['content'] internal_send_message(realm_for_email("feedback@zulip.com"), "feedback@zulip.com", - "stream", "support", subject, content) + "stream", settings.FEEDBACK_STREAM, subject, content) diff --git a/zerver/worker/queue_processors.py b/zerver/worker/queue_processors.py index 42103e9bf1..acbf185488 100644 --- a/zerver/worker/queue_processors.py +++ b/zerver/worker/queue_processors.py @@ -10,6 +10,7 @@ from zerver.models import get_user_profile_by_email, \ UserMessage, Message, Realm from zerver.lib.context_managers import lockfile from zerver.lib.error_notify import do_report_error +from zerver.lib.feedback import deliver_feedback_by_zulip from zerver.lib.queue import SimpleQueueClient, queue_json_publish from zerver.lib.timestamp import timestamp_to_datetime from zerver.lib.notifications import handle_missedmessage_emails, enqueue_welcome_emails, \ @@ -251,6 +252,8 @@ class FeedbackBot(QueueProcessingWorker): headers = {'Reply-To': '"%s" <%s>' % (event["sender_full_name"], event["sender_email"])} msg = EmailMessage(subject, content, from_email, [to_email], headers=headers) msg.send() + if settings.FEEDBACK_STREAM is not None: + deliver_feedback_by_zulip(event) @assign_queue('error_reports') class ErrorReporter(QueueProcessingWorker): diff --git a/zilencer/urls.py b/zilencer/urls.py index cdcf4770ec..12d6131f3d 100644 --- a/zilencer/urls.py +++ b/zilencer/urls.py @@ -10,8 +10,6 @@ i18n_urlpatterns = [] # type: Any # Zilencer views following the REST API style v1_api_and_json_patterns = [ - url('^deployment/feedback$', rest_dispatch, - {'POST': 'zilencer.views.submit_feedback'}), url('^deployment/report_error$', rest_dispatch, {'POST': 'zerver.views.report.report_error'}), ] diff --git a/zilencer/views.py b/zilencer/views.py index 0deebb9987..959de186d9 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -7,17 +7,10 @@ from zilencer.models import Deployment from zerver.decorator import has_request_variables, REQ from zerver.lib.error_notify import do_report_error -from zerver.lib.feedback import deliver_feedback_by_zulip from zerver.lib.validator import check_dict from typing import Any, Dict, Text -@has_request_variables -def submit_feedback(request, deployment, message=REQ(validator=check_dict([]))): - # type: (HttpRequest, Deployment, Dict[str, Text]) -> HttpResponse - deliver_feedback_by_zulip(message) - return HttpResponse(message['sender_email']) - @has_request_variables def report_error(request, deployment, type=REQ(), report=REQ(validator=check_dict([]))): # type: (HttpRequest, Deployment, Text, Dict[str, Any]) -> HttpResponse diff --git a/zproject/settings.py b/zproject/settings.py index aee5e5edd4..52b6e51340 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -151,6 +151,7 @@ DEFAULT_SETTINGS = {'TWITTER_CONSUMER_KEY': '', 'SEND_MISSED_MESSAGE_EMAILS_AS_USER': False, 'SERVER_EMAIL': None, 'FEEDBACK_EMAIL': None, + 'FEEDBACK_STREAM': None, 'WELCOME_EMAIL_SENDER': None, 'EMAIL_DELIVERER_DISABLED': False, 'ENABLE_GRAVATAR': True,