Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
message_report: Return message ID from send_message_report.
Danish52473002c0c1
diff --git a/api_docs/unmerged.d/ZF-f6b664.md b/api_docs/unmerged.d/ZF-f6b664.mdnew file mode 100644index 00000000000..9c39590c199--- /dev/null+++ b/api_docs/unmerged.d/ZF-f6b664.md@@ -0,0 +1,3 @@+* [`POST /messages/{message_id}/report`](/api/report-message): This endpoint+ now returns an error if the message report fails to be sent to the+ moderation request channel.diff --git a/zerver/lib/message_report.py b/zerver/lib/message_report.pyindex 7bda86c08e7..ec42ea01ac1 100644--- a/zerver/lib/message_report.py+++ b/zerver/lib/message_report.py@@ -34,7 +34,7 @@ def send_message_report(reported_message: Message,report_type: str,description: str,-) -> None:+) -> int | None:moderation_request_channel = realm.moderation_request_channelassert moderation_request_channel is not None@@ -150,7 +150,7 @@ def send_message_report(if moderation_request_channel.topics_policy == StreamTopicsPolicyEnum.empty_topic_only.value:topic_name = ""- internal_send_stream_message(+ return internal_send_stream_message(sender=get_system_bot(settings.NOTIFICATION_BOT, moderation_request_channel.realm.id),stream=moderation_request_channel,topic_name=topic_name,diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex d8d38216034..9e57b53f0e2 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -10982,6 +10982,10 @@ paths:parameter is required. Clients should also enforce and communicate thisbehavior in the UI.+ **Changes**: In Zulip 13.0 (feature level ZF-f6b664), this endpoint+ now returns an error if the message report fails to be sent to the+ moderation request channel.+**Changes**: New in Zulip 11.0 (feature level 382). This API builds onthe `moderation_request_channel` realm setting, which was added infeature level 331.diff --git a/zerver/tests/test_message_report.py b/zerver/tests/test_message_report.pyindex e166133ada7..01f187b9b0d 100644--- a/zerver/tests/test_message_report.py+++ b/zerver/tests/test_message_report.py@@ -1,4 +1,5 @@from datetime import timedelta+from unittest import mockimport time_machinefrom django.conf import settings@@ -594,3 +595,15 @@ class ReportMessageTest(ZulipTestCase):self.assertEqual(report_msg.sender_id, notification_bot.id)self.assertEqual(report_msg.topic_name(), "")self.assertIn("reported", report_msg.content)++ def test_failed_internal_send_raises_error(self) -> None:+ with mock.patch(+ "zerver.lib.message_report.internal_send_stream_message",+ return_value=None,+ ):+ result = self.report_message(+ self.hamlet,+ self.reported_message_id,+ report_type="spam",+ )+ self.assert_json_error(result, "Failed to send the message report.")diff --git a/zerver/views/message_report.py b/zerver/views/message_report.pyindex af4e15cd8fc..a5128b4a374 100644--- a/zerver/views/message_report.py+++ b/zerver/views/message_report.py@@ -33,7 +33,7 @@ def report_message_backend(reported_message = access_message(user_profile, message_id, is_modifying_message=False)with override_language(user_profile.realm.default_language):- send_message_report(+ message_report_id = send_message_report(user_profile,user_profile.realm,reported_message,@@ -41,4 +41,6 @@ def report_message_backend(description,)+ if message_report_id is None:+ raise JsonableError(_("Failed to send the message report."))return json_success(request)