mirror of https://github.com/zulip/zulip.git
slack webhooks: Eliminate unnecessary use of Service model.
The user ID of the bot user is a much more useful value to be sending to the third-party API here.
This commit is contained in:
parent
b6ce93e029
commit
bdc95b5d72
|
@ -85,7 +85,6 @@ class SlackOutgoingWebhookService(OutgoingWebhookServiceInterface):
|
||||||
if event['message']['type'] == 'private':
|
if event['message']['type'] == 'private':
|
||||||
raise NotImplementedError("Private messaging service not supported.")
|
raise NotImplementedError("Private messaging service not supported.")
|
||||||
|
|
||||||
service = get_service_profile(event['user_profile_id'], str(self.service_name))
|
|
||||||
request_data = [("token", self.token),
|
request_data = [("token", self.token),
|
||||||
("team_id", event['message']['sender_realm_str']),
|
("team_id", event['message']['sender_realm_str']),
|
||||||
("team_domain", email_to_domain(event['message']['sender_email'])),
|
("team_domain", email_to_domain(event['message']['sender_email'])),
|
||||||
|
@ -96,7 +95,7 @@ class SlackOutgoingWebhookService(OutgoingWebhookServiceInterface):
|
||||||
("user_name", event['message']['sender_full_name']),
|
("user_name", event['message']['sender_full_name']),
|
||||||
("text", event['command']),
|
("text", event['command']),
|
||||||
("trigger_word", event['trigger']),
|
("trigger_word", event['trigger']),
|
||||||
("service_id", service.id),
|
("service_id", event['user_profile_id']),
|
||||||
]
|
]
|
||||||
|
|
||||||
return rest_operation, request_data
|
return rest_operation, request_data
|
||||||
|
|
|
@ -76,8 +76,7 @@ class TestSlackOutgoingWebhookService(ZulipTestCase):
|
||||||
user_profile=None,
|
user_profile=None,
|
||||||
service_name='test-service')
|
service_name='test-service')
|
||||||
|
|
||||||
@mock.patch('zerver.lib.outgoing_webhook.get_service_profile', return_value=mock_service)
|
def test_process_event(self) -> None:
|
||||||
def test_process_event(self, mock_get_service_profile: mock.Mock) -> None:
|
|
||||||
rest_operation, request_data = self.handler.process_event(self.event)
|
rest_operation, request_data = self.handler.process_event(self.event)
|
||||||
|
|
||||||
self.assertEqual(rest_operation['base_url'], 'http://example.domain.com')
|
self.assertEqual(rest_operation['base_url'], 'http://example.domain.com')
|
||||||
|
@ -92,7 +91,7 @@ class TestSlackOutgoingWebhookService(ZulipTestCase):
|
||||||
self.assertEqual(request_data[7][1], "Sample User") # user_name
|
self.assertEqual(request_data[7][1], "Sample User") # user_name
|
||||||
self.assertEqual(request_data[8][1], "@**test**") # text
|
self.assertEqual(request_data[8][1], "@**test**") # text
|
||||||
self.assertEqual(request_data[9][1], "mention") # trigger_word
|
self.assertEqual(request_data[9][1], "mention") # trigger_word
|
||||||
self.assertEqual(request_data[10][1], mock_service.id) # service_id
|
self.assertEqual(request_data[10][1], 12) # user_profile_id
|
||||||
|
|
||||||
def test_process_success(self) -> None:
|
def test_process_success(self) -> None:
|
||||||
response = mock.Mock(spec=Response)
|
response = mock.Mock(spec=Response)
|
||||||
|
|
Loading…
Reference in New Issue