webhooks: Migrate to check_send_stream_message.

This commit migrates all webhooks to use check_send_stream_message
instead of check_send_message. The only two webhooks that still
use check_send_message are our yo and teamcity webhooks. They
both use check_send_message for private messages.
This commit is contained in:
Eeshan Garg 2017-09-29 23:48:16 -02:30 committed by showell
parent 24aff0d0a2
commit 86c2c7ad34
53 changed files with 188 additions and 192 deletions

View File

@ -2,7 +2,7 @@
from typing import Dict, Any, Text
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -18,7 +18,8 @@ def api_airbrake_webhook(request, user_profile,
# type: (HttpRequest, UserProfile, Dict[str, Any], Text) -> HttpResponse
subject = get_subject(payload)
body = get_body(payload)
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client,
stream, subject, body)
return json_success()
def get_subject(payload):

View File

@ -4,7 +4,7 @@ import re
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -19,7 +19,8 @@ def api_appfollow_webhook(request, user_profile, stream=REQ(default="appfollow")
message = payload["text"]
app_name = re.search('\A(.+)', message).group(0)
check_send_message(user_profile, request.client, "stream", [stream], app_name, convert_markdown(message))
check_send_stream_message(user_profile, request.client, stream,
app_name, convert_markdown(message))
return json_success()
def convert_markdown(text):

View File

@ -3,7 +3,7 @@ import logging
from typing import Any, Dict, Text
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -48,7 +48,8 @@ def api_basecamp_webhook(request, user_profile, payload=REQ(argument_type='body'
logging.warning("Basecamp handling of {} event is not implemented".format(event))
return json_success()
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client,
stream, subject, body)
return json_success()
def get_project_name(payload):

View File

@ -103,47 +103,47 @@ class BeanstalkHookTests(WebhookTestCase):
content_type=None,
**self.api_auth(self.TEST_USER_EMAIL))
@patch('zerver.webhooks.beanstalk.view.check_send_message')
def test_git_single_filtered_by_branches_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.beanstalk.view.check_send_stream_message')
def test_git_single_filtered_by_branches_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,development')
payload = self.get_body('git_singlecommit')
result = self.client_post(self.url, payload,
**self.api_auth(self.TEST_USER_EMAIL))
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.beanstalk.view.check_send_message')
@patch('zerver.webhooks.beanstalk.view.check_send_stream_message')
def test_git_multiple_committers_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,development')
payload = self.get_body('git_multiple_committers')
result = self.client_post(self.url, payload,
**self.api_auth(self.TEST_USER_EMAIL))
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.beanstalk.view.check_send_message')
@patch('zerver.webhooks.beanstalk.view.check_send_stream_message')
def test_git_multiple_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,development')
payload = self.get_body('git_multiple')
result = self.client_post(self.url, payload,
**self.api_auth(self.TEST_USER_EMAIL))
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.beanstalk.view.check_send_message')
@patch('zerver.webhooks.beanstalk.view.check_send_stream_message')
def test_git_more_than_limit_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,development')
payload = self.get_body('git_morethanlimitcommits')
result = self.client_post(self.url, payload,
**self.api_auth(self.TEST_USER_EMAIL))
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
def test_svn_addremove(self):

View File

@ -2,7 +2,7 @@
from django.http import HttpRequest, HttpResponse
from zerver.models import get_client, UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.lib.validator import check_dict
from zerver.decorator import REQ, has_request_variables, authenticated_rest_api_view
@ -72,6 +72,6 @@ def api_beanstalk_webhook(request, user_profile,
subject = "svn r%s" % (revision,)
content = "%s pushed [revision %s](%s):\n\n> %s" % (author, revision, url, short_commit_msg)
check_send_message(user_profile, get_client("ZulipBeanstalkWebhook"), "stream",
["commits"], subject, content)
check_send_stream_message(user_profile, get_client("ZulipBeanstalkWebhook"),
"commits", subject, content)
return json_success()

View File

@ -52,8 +52,8 @@ class BitbucketHookTests(WebhookTestCase):
expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)"
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
@patch('zerver.webhooks.bitbucket.view.check_send_message')
def test_bitbucket_on_push_event_filtered_by_branches_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.bitbucket.view.check_send_stream_message')
def test_bitbucket_on_push_event_filtered_by_branches_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
fixture_name = 'push'
payload = self.get_body(fixture_name)
@ -62,12 +62,12 @@ class BitbucketHookTests(WebhookTestCase):
result = self.client_post(self.url, payload,
content_type="application/json,",
**self.api_auth(self.TEST_USER_EMAIL))
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.bitbucket.view.check_send_message')
@patch('zerver.webhooks.bitbucket.view.check_send_stream_message')
def test_bitbucket_push_commits_above_limit_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
fixture_name = 'push_commits_above_limit'
payload = self.get_body(fixture_name)
@ -76,7 +76,7 @@ class BitbucketHookTests(WebhookTestCase):
result = self.client_post(self.url, payload,
content_type="application/json,",
**self.api_auth(self.TEST_USER_EMAIL))
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
def get_body(self, fixture_name):

View File

@ -1,10 +1,9 @@
from typing import Any, Mapping, Text, Optional
from django.http import HttpRequest, HttpResponse
from zerver.models import get_client, UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.lib.validator import check_dict
from zerver.decorator import REQ, has_request_variables, authenticated_rest_api_view
@ -45,6 +44,6 @@ def api_bitbucket_webhook(request, user_profile, payload=REQ(validator=check_dic
content = get_push_commits_event_message(payload['user'], None, branch, commits)
subject = SUBJECT_WITH_BRANCH_TEMPLATE.format(repo=repository['name'], branch=branch)
check_send_message(user_profile, get_client("ZulipBitBucketWebhook"), "stream",
[stream], subject, content)
check_send_stream_message(user_profile, get_client("ZulipBitBucketWebhook"),
stream, subject, content)
return json_success()

View File

@ -255,52 +255,52 @@ class Bitbucket2HookTests(WebhookTestCase):
self.EXPECTED_SUBJECT,
expected_message, **kwargs)
@patch('zerver.webhooks.bitbucket2.view.check_send_message')
@patch('zerver.webhooks.bitbucket2.view.check_send_stream_message')
def test_bitbucket2_on_push_event_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('push')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.bitbucket2.view.check_send_message')
@patch('zerver.webhooks.bitbucket2.view.check_send_stream_message')
def test_bitbucket2_on_push_commits_above_limit_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('push_commits_above_limit')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.bitbucket2.view.check_send_message')
@patch('zerver.webhooks.bitbucket2.view.check_send_stream_message')
def test_bitbucket2_on_force_push_event_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('force_push')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.bitbucket2.view.check_send_message')
@patch('zerver.webhooks.bitbucket2.view.check_send_stream_message')
def test_bitbucket2_on_push_multiple_committers_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('push_multiple_committers')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.bitbucket2.view.check_send_message')
@patch('zerver.webhooks.bitbucket2.view.check_send_stream_message')
def test_bitbucket2_on_push_multiple_committers_with_others_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('push_multiple_committers_with_others')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)

View File

@ -5,7 +5,7 @@ from six.moves import zip
from typing import Any, Callable, Dict, List, Optional, Text
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -47,7 +47,8 @@ def api_bitbucket2_webhook(request, user_profile, payload=REQ(argument_type='bod
if type != 'push':
subject = get_subject_based_on_type(payload, type)
body = get_body_based_on_type(type)(payload)
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client,
stream, subject, body)
else:
branch = get_branch_name_for_push_event(payload)
if branch and branches:
@ -56,7 +57,8 @@ def api_bitbucket2_webhook(request, user_profile, payload=REQ(argument_type='bod
subjects = get_push_subjects(payload)
bodies_list = get_push_bodies(payload)
for body, subject in zip(bodies_list, subjects):
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client,
stream, subject, body)
return json_success()
def get_subject_for_branch_specified_events(payload, branch_name=None):

View File

@ -3,7 +3,7 @@
from django.http import HttpRequest, HttpResponse
from typing import Any, Dict, Text
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -25,7 +25,7 @@ def api_circleci_webhook(request, user_profile, payload=REQ(argument_type='body'
subject = get_subject(payload)
body = get_body(payload)
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()
def get_subject(payload):

View File

@ -4,7 +4,7 @@ from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from typing import Any, Dict
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -32,7 +32,7 @@ def api_codeship_webhook(request, user_profile, payload=REQ(argument_type='body'
subject = get_subject_for_http_request(payload)
body = get_body_for_http_request(payload)
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -36,6 +36,6 @@ def api_crashlytics_webhook(request, user_profile, payload=REQ(argument_type='bo
url=issue_body['url']
)
check_send_message(user_profile, request.client, 'stream', [stream],
subject, body)
check_send_stream_message(user_profile, request.client, stream,
subject, body)
return json_success()

View File

@ -1,5 +1,5 @@
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -31,6 +31,6 @@ def api_delighted_webhook(request, user_profile,
BODY_TEMPLATE = body_template(selected_payload['score'])
body = BODY_TEMPLATE.format(**selected_payload)
check_send_message(user_profile, request.client, 'stream', [stream],
topic, body)
check_send_stream_message(user_profile, request.client, stream,
topic, body)
return json_success()

View File

@ -1,7 +1,7 @@
# Webhooks for external integrations.
from django.http import HttpRequest, HttpResponse
from zerver.models import get_client, UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, authenticated_rest_api_view
@ -18,6 +18,6 @@ def api_deskdotcom_webhook(request, user_profile, data=REQ(),
topic=REQ(default="Desk.com notification"),
stream=REQ(default="desk.com")):
# type: (HttpRequest, UserProfile, Text, Text, Text) -> HttpResponse
check_send_message(user_profile, get_client("ZulipDeskWebhook"), "stream",
[stream], topic, data)
check_send_stream_message(user_profile, get_client("ZulipDeskWebhook"),
stream, topic, data)
return json_success()

View File

@ -4,7 +4,7 @@ from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.models import get_client, UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.lib.notifications import convert_html_to_markdown
from zerver.decorator import REQ, has_request_variables, authenticated_rest_api_view
@ -144,6 +144,6 @@ def api_freshdesk_webhook(request, user_profile, payload=REQ(argument_type='body
# Not an event we know handle; do nothing.
return json_success()
check_send_message(user_profile, get_client("ZulipFreshdeskWebhook"), "stream",
[stream], subject, content)
check_send_stream_message(user_profile, get_client("ZulipFreshdeskWebhook"),
stream, subject, content)
return json_success()

View File

@ -248,70 +248,70 @@ class GithubWebhookTest(WebhookTestCase):
HTTP_X_GITHUB_EVENT='pull_request'
)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_pull_request_labeled_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_pull_request_labeled_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
payload = self.get_body('labeled_pull_request')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='pull_request', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_pull_request_unlabeled_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_pull_request_unlabeled_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
payload = self.get_body('unlabeled_pull_request')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='pull_request', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_pull_request_request_review_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_pull_request_request_review_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
payload = self.get_body('request_review_pull_request')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='pull_request', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_pull_request_request_review_remove_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_pull_request_request_review_remove_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
payload = self.get_body('request_review_removed_pull_request')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='pull_request', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_push_1_commit_filtered_by_branches_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_push_1_commit_filtered_by_branches_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push_1_commit')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_push_50_commits_filtered_by_branches_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_push_50_commits_filtered_by_branches_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push_50_commits')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_push_multiple_comitters_filtered_by_branches_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_push_multiple_comitters_filtered_by_branches_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push_multiple_committers')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.github_webhook.view.check_send_message')
def test_push_multiple_comitters_with_others_filtered_by_branches_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.github_webhook.view.check_send_stream_message')
def test_push_multiple_comitters_with_others_filtered_by_branches_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push_multiple_committers_with_others')
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)

View File

@ -3,7 +3,7 @@ import logging
from functools import partial
from typing import Any, Callable, Text, Dict, Optional
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.lib.request import JsonableError
from zerver.models import UserProfile
@ -406,7 +406,7 @@ def api_github_webhook(
if event is not None:
subject = get_subject_based_on_type(payload, event)
body = get_body_function_based_on_type(event)(payload)
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()
def get_event(request, payload, branches):

View File

@ -379,22 +379,22 @@ class GitlabHookTests(WebhookTestCase):
HTTP_X_GITLAB_EVENT="Pipeline Hook"
)
@patch('zerver.webhooks.gitlab.view.check_send_message')
@patch('zerver.webhooks.gitlab.view.check_send_stream_message')
def test_push_event_message_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push')
result = self.client_post(self.url, payload, HTTP_X_GITLAB_EVENT='Push Hook', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.gitlab.view.check_send_message')
@patch('zerver.webhooks.gitlab.view.check_send_stream_message')
def test_push_commits_more_than_limit_message_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='master,development')
payload = self.get_body('push_commits_more_than_limit')
result = self.client_post(self.url, payload, HTTP_X_GITLAB_EVENT='Push Hook', content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)

View File

@ -1,5 +1,5 @@
from functools import partial
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variables
from zerver.lib.webhooks.git import get_push_commits_event_message, EMPTY_SHA,\
@ -288,7 +288,7 @@ def api_gitlab_webhook(request, user_profile,
if event is not None:
body = get_body_based_on_event(event)(payload)
subject = get_subject_based_on_event(event, payload)
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()
def get_body_based_on_event(event):

View File

@ -91,34 +91,34 @@ from `feature` to `master`"""
from `feature` to `master`"""
self.send_and_test_stream_message('pull_request_merged', expected_subject, expected_message, HTTP_X_GOGS_EVENT='pull_request')
@patch('zerver.webhooks.gogs.view.check_send_message')
def test_push_filtered_by_branches_ignore(self, check_send_message_mock):
@patch('zerver.webhooks.gogs.view.check_send_stream_message')
def test_push_filtered_by_branches_ignore(self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,development')
payload = self.get_body('push')
result = self.client_post(self.url, payload, HTTP_X_GOGS_EVENT='push',
content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.gogs.view.check_send_message')
@patch('zerver.webhooks.gogs.view.check_send_stream_message')
def test_push_commits_more_than_limits_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,development')
payload = self.get_body('push_commits_more_than_limits')
result = self.client_post(self.url, payload, HTTP_X_GOGS_EVENT='push',
content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.gogs.view.check_send_message')
@patch('zerver.webhooks.gogs.view.check_send_stream_message')
def test_push_multiple_committers_filtered_by_branches_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,development')
payload = self.get_body('push_commits_multiple_committers')
result = self.client_post(self.url, payload, HTTP_X_GOGS_EVENT='push',
content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -96,5 +96,5 @@ def api_gogs_webhook(request, user_profile,
else:
return json_error(_('Invalid event "{}" in request headers').format(event))
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -1,5 +1,5 @@
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -26,6 +26,6 @@ def api_gosquared_webhook(request, user_profile,
if topic is None:
topic = 'GoSquared - {website_name}'.format(website_name=domain_name)
check_send_message(user_profile, request.client, 'stream', [stream],
topic, body)
check_send_stream_message(user_profile, request.client, stream,
topic, body)
return json_success()

View File

@ -1,9 +1,8 @@
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from typing import Any, Dict, List
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -55,5 +54,5 @@ def api_greenhouse_webhook(request, user_profile,
if topic is None:
topic = "{} - {}".format(action, str(candidate['id']))
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -1,5 +1,5 @@
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -50,6 +50,5 @@ def api_hellosign_webhook(request, user_profile,
model_payload = ready_payload(payload['signature_request']['signatures'], payload)
body = format_body(payload['signature_request']['signatures'], model_payload)
topic = topic or model_payload['contract_title']
check_send_message(user_profile, request.client, 'stream', [stream],
topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.validator import check_dict, check_string
@ -24,6 +24,6 @@ def api_helloworld_webhook(request, user_profile,
body += body_template.format(**payload)
# send the message
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -3,7 +3,7 @@ from typing import Text
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -17,5 +17,5 @@ def api_heroku_webhook(request, user_profile, stream=REQ(default="heroku"),
template = "{} deployed version {} of [{}]({})\n> {}"
content = template.format(user, head, app, url, git_log)
check_send_message(user_profile, request.client, "stream", [stream], app, content)
check_send_stream_message(user_profile, request.client, stream, app, content)
return json_success()

View File

@ -1,5 +1,5 @@
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.validator import check_dict, check_string
@ -26,7 +26,7 @@ def api_homeassistant_webhook(request, user_profile,
topic = "homeassistant"
# send the message
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
# return json result
return json_success()

View File

@ -1,7 +1,7 @@
from django.utils.translation import ugettext as _
from typing import Any, Callable, Dict
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -19,5 +19,5 @@ def api_iftt_app_webhook(request, user_profile,
return json_error(_("Subject can't be empty"))
if content is None:
return json_error(_("Content can't be empty"))
check_send_message(user_profile, request.client, "stream", [stream], subject, content)
check_send_stream_message(user_profile, request.client, stream, subject, content)
return json_success()

View File

@ -7,7 +7,7 @@ from django.conf import settings
from django.http import HttpRequest, HttpResponse
from zerver.models import UserProfile, get_user, Realm
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import api_key_only_webhook_view, has_request_variables, REQ
@ -266,5 +266,5 @@ def api_jira_webhook(request, user_profile,
logging.warning("Got JIRA event type we don't support: {}".format(event))
return json_success()
check_send_message(user_profile, request.client, "stream", [stream], subject, content)
check_send_stream_message(user_profile, request.client, stream, subject, content)
return json_success()

View File

@ -1,4 +1,3 @@
from datetime import datetime
from typing import Any, Dict, List, Optional, Callable, Tuple, Text
from six.moves import zip
@ -9,7 +8,7 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variables
from zerver.lib.response import json_success, json_error
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.models import UserProfile
import ujson
@ -180,5 +179,5 @@ def api_librato_webhook(request, user_profile, payload=REQ(converter=ujson.loads
except Exception as e:
return json_error(_(str(e)))
check_send_message(user_profile, request.client, "stream", [stream], topic, content)
check_send_stream_message(user_profile, request.client, stream, topic, content)
return json_success()

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.validator import check_dict, check_string
@ -23,6 +23,6 @@ def api_mention_webhook(request, user_profile,
body = '**[%s](%s)**:\n%s' % (title, source_url, description)
# send the message
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -4,7 +4,7 @@ from typing import Any, Callable, Dict, Iterable, Optional, Tuple, Text
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.lib.validator import check_dict
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -32,6 +32,5 @@ def api_newrelic_webhook(request, user_profile, stream=REQ(default='newrelic'),
else:
return json_error(_("Unknown webhook request"))
check_send_message(user_profile, request.client, "stream",
[stream], subject, content)
check_send_stream_message(user_profile, request.client, stream, subject, content)
return json_success()

View File

@ -1,5 +1,5 @@
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.validator import check_dict, check_string
@ -46,6 +46,6 @@ def api_opsgenie_webhook(request, user_profile,
"{tags}"
body += body_template.format(**info)
# send the message
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import Client, UserProfile
@ -76,8 +76,7 @@ def send_raw_pagerduty_json(user_profile, client, stream, message, topic):
u'```\n'
u'%s\n'
u'```') % (ujson.dumps(message, indent=2),)
check_send_message(user_profile, client, 'stream',
[stream], subject, body)
check_send_stream_message(user_profile, client, stream, subject, body)
def send_formated_pagerduty(user_profile, client, stream, message_type, format_dict, topic):
@ -102,8 +101,7 @@ def send_formated_pagerduty(user_profile, client, stream, message_type, format_d
subject = topic or u'incident {incident_num}'.format(**format_dict)
body = template.format(**format_dict)
check_send_message(user_profile, client, 'stream',
[stream], subject, body)
check_send_stream_message(user_profile, client, stream, subject, body)
@api_key_only_webhook_view('PagerDuty')

View File

@ -1,5 +1,5 @@
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.validator import check_dict, check_string
@ -36,7 +36,7 @@ def api_papertrail_webhook(request, user_profile,
post = '\n'.join(message)
# send the message
check_send_message(user_profile, request.client, 'stream', [stream], topic, post)
check_send_stream_message(user_profile, request.client, stream, topic, post)
# return json result
return json_success()

View File

@ -1,10 +1,10 @@
# Webhooks for external integrations.
# Webhooks pfor external integrations.
from typing import Any, Dict, Text
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -44,7 +44,7 @@ def api_pingdom_webhook(request, user_profile, payload=REQ(argument_type='body')
else:
return json_error(_('Unsupported check_type: {check_type}').format(check_type=check_type))
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()

View File

@ -3,7 +3,7 @@
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variables
from zerver.models import UserProfile
@ -173,6 +173,5 @@ def api_pivotal_webhook(request, user_profile, stream=REQ()):
if subject is None or content is None:
return json_error(_("Unable to handle Pivotal payload"))
check_send_message(user_profile, request.client, "stream",
[stream], subject, content)
check_send_stream_message(user_profile, request.client, stream, subject, content)
return json_success()

View File

@ -4,7 +4,7 @@ from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.models import get_client
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -52,6 +52,5 @@ def api_semaphore_webhook(request, user_profile,
commit_url, message)
subject = u"%s/%s" % (project_name, branch_name)
check_send_message(user_profile, request.client, "stream",
[stream], subject, content)
check_send_stream_message(user_profile, request.client, stream, subject, content)
return json_success()

View File

@ -1,7 +1,7 @@
# Webhooks for external integrations.
from django.http import HttpRequest, HttpResponse
from zerver.models import UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from typing import Any, Dict
@ -16,5 +16,5 @@ def api_sentry_webhook(request, user_profile,
body = "New {} [issue]({}): {}.".format(payload['level'].upper(),
payload.get('url'),
payload.get('message'))
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()

View File

@ -1,7 +1,7 @@
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message, create_stream_if_needed
from zerver.lib.actions import check_send_stream_message, create_stream_if_needed
from zerver.lib.response import json_success, json_error
from zerver.lib.validator import check_string, check_int
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -30,5 +30,5 @@ def api_slack_webhook(request, user_profile,
subject = _("Message from Slack")
content = ZULIP_MESSAGE_TEMPLATE.format(message_sender=user_name, text=text)
check_send_message(user_profile, request.client, "stream", [stream], subject, content)
check_send_stream_message(user_profile, request.client, stream, subject, content)
return json_success()

View File

@ -4,7 +4,7 @@ from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.models import UserProfile, Client
@ -61,11 +61,11 @@ def api_solano_webhook(request, user_profile,
body = template.format(author, commit_id, commit_url, status, emoji, build_log)
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()
def handle_test_event(user_profile, client, stream, topic):
# type: (UserProfile, Client, str, str) -> HttpResponse
body = 'Solano webhook set up correctly'
check_send_message(user_profile, client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, client, stream, topic, body)
return json_success()

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.validator import check_dict, check_string
@ -38,6 +38,6 @@ def api_splunk_webhook(request, user_profile,
host = host, source = source, raw = raw)
# send the message
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -159,7 +159,7 @@ def api_stripe_webhook(request, user_profile,
if body is None:
return json_error(_("We don't support {} event".format(event_type)))
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -23,7 +23,7 @@ from typing import Any, Dict, List, Mapping, Optional, Tuple, Text
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -44,7 +44,7 @@ def api_taiga_webhook(request, user_profile, message=REQ(argument_type='body'),
content_lines.append(generate_content(event) + '\n')
content = "".join(sorted(content_lines))
check_send_message(user_profile, request.client, 'stream', [stream], topic, content)
check_send_stream_message(user_profile, request.client, stream, topic, content)
return json_success()

View File

@ -5,7 +5,7 @@ from django.http import HttpRequest, HttpResponse
from typing import Any, Dict, List, Optional
from zerver.models import UserProfile, Realm
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_message, check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -96,5 +96,5 @@ def api_teamcity_webhook(request, user_profile, payload=REQ(argument_type='body'
check_send_message(user_profile, request.client, 'private', [teamcity_user.email], topic, body)
return json_success()
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -2,7 +2,7 @@
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from zerver.models import UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from typing import Optional
@ -22,5 +22,5 @@ def api_transifex_webhook(request, user_profile,
body = "Resource {} fully reviewed.".format(resource)
else:
return json_error(_("Transifex wrong request"))
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()

View File

@ -3,7 +3,7 @@
from django.http import HttpRequest, HttpResponse
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.lib.validator import check_dict, check_string, check_bool
from zerver.models import UserProfile
@ -52,5 +52,5 @@ def api_travis_webhook(request, user_profile,
message['build_url']
)
check_send_message(user_profile, request.client, 'stream', [stream], topic, body)
check_send_stream_message(user_profile, request.client, stream, topic, body)
return json_success()

View File

@ -107,22 +107,22 @@ class TrelloHookTests(WebhookTestCase):
expected_message = u"TomaszKolek renamed the board from Welcome Board to [New name](https://trello.com/b/iqXXzYEj)."
self.send_and_test_stream_message('renaming_board', u"New name", expected_message)
@patch('zerver.webhooks.trello.view.check_send_message')
@patch('zerver.webhooks.trello.view.check_send_stream_message')
def test_trello_webhook_when_card_is_moved_within_single_list_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
payload = self.get_body('moving_card_within_single_list')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
@patch('zerver.webhooks.trello.view.check_send_message')
@patch('zerver.webhooks.trello.view.check_send_stream_message')
def test_trello_webhook_when_board_background_is_changed_ignore(
self, check_send_message_mock):
self, check_send_stream_message_mock):
# type: (MagicMock) -> None
payload = self.get_body('change_board_background_image')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assertFalse(check_send_stream_message_mock.called)
self.assert_json_success(result)
def test_trello_webhook_when_description_was_added_to_card(self):

View File

@ -3,7 +3,7 @@ import ujson
from typing import Mapping, Any, Tuple, Text, Optional
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.decorator import return_success_on_head_request
from zerver.lib.response import json_success, json_error
from zerver.models import UserProfile
@ -29,7 +29,7 @@ def api_trello_webhook(request, user_profile, payload=REQ(argument_type='body'),
except UnsupportedAction:
return json_error(_('Unsupported action_type: {action_type}'.format(action_type=action_type)))
check_send_message(user_profile, request.client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, request.client, stream, subject, body)
return json_success()
def get_subject_and_body(payload, action_type):

View File

@ -5,7 +5,7 @@ from typing import Any, Dict, List
from django.http import HttpRequest, HttpResponse
from django.utils.translation import ugettext as _
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.exceptions import JsonableError
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -18,7 +18,7 @@ def send_message_for_event(event, user_profile, client, stream):
event_type = get_event_type(event)
subject = SUBJECT_TEMPLATE.format(service_url=event['check']['url'])
body = EVENT_TYPE_BODY_MAPPER[event_type](event)
check_send_message(user_profile, client, 'stream', [stream], subject, body)
check_send_stream_message(user_profile, client, stream, subject, body)
def get_body_for_up_event(event):
# type: (Dict[str, Any]) -> str

View File

@ -2,7 +2,7 @@
from django.utils.translation import ugettext as _
from django.http import HttpRequest, HttpResponse
from zerver.models import get_client, UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
@ -41,6 +41,6 @@ def api_wordpress_webhook(request, user_profile,
else:
return json_error(_("Unknown WordPress webhook action: " + hook))
check_send_message(user_profile, get_client("ZulipWordPressWebhook"), "stream",
[stream], topic, data)
check_send_stream_message(user_profile, get_client("ZulipWordPressWebhook"),
stream, topic, data)
return json_success()

View File

@ -1,7 +1,7 @@
from django.utils.translation import ugettext as _
from typing import Any, Callable, Dict
from django.http import HttpRequest, HttpResponse
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success, json_error
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile
@ -19,5 +19,5 @@ def api_zapier_webhook(request, user_profile,
return json_error(_("Subject can't be empty"))
if content is None:
return json_error(_("Content can't be empty"))
check_send_message(user_profile, request.client, "stream", [stream], subject, content)
check_send_stream_message(user_profile, request.client, stream, subject, content)
return json_success()

View File

@ -1,6 +1,6 @@
# Webhooks for external integrations.
from zerver.models import get_client, UserProfile
from zerver.lib.actions import check_send_message
from zerver.lib.actions import check_send_stream_message
from zerver.lib.response import json_success
from zerver.decorator import authenticated_rest_api_view, REQ, has_request_variables
from django.http import HttpRequest, HttpResponse
@ -23,6 +23,6 @@ def api_zendesk_webhook(request, user_profile, ticket_title=REQ(), ticket_id=REQ
user's configured message to zulip.
"""
subject = truncate('#%s: %s' % (ticket_id, ticket_title), 60)
check_send_message(user_profile, get_client('ZulipZenDeskWebhook'), 'stream',
[stream], subject, message)
check_send_stream_message(user_profile, get_client('ZulipZenDeskWebhook'),
stream, subject, message)
return json_success()