mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	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:
		@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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):
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user