Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message: Check mandatory_topics setting in backend as well.

Sahil Batra9f0d4989945d
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index 7f6d2fba818..6b90c7edf13 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -3424,6 +3424,9 @@ def check_message(
# else can sneak past the access check.
assert sender.bot_type == sender.OUTGOING_WEBHOOK_BOT
+ if realm.mandatory_topics and topic_name == "(no topic)":
+ raise JsonableError(_("Topics are required in this organization"))
+
elif addressee.is_private():
user_profiles = addressee.user_profiles()
mirror_message = client and client.name in [
diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py
index 6ea1ae9f786..74402f32328 100644
--- a/zerver/tests/test_message_send.py
+++ b/zerver/tests/test_message_send.py
@@ -2732,3 +2732,23 @@ class CheckMessageTest(ZulipTestCase):
test_bot.realm.deactivated = True
send_rate_limited_pm_notification_to_bot_owner(test_bot, good_realm, content)
self.assertEqual(test_bot.last_reminder, None)
+
+ def test_no_topic_message(self) -> None:
+ realm = get_realm("zulip")
+ sender = self.example_user("iago")
+ client = make_client(name="test suite")
+ stream = get_stream("Denmark", realm)
+ topic_name = "(no topic)"
+ message_content = "whatever"
+ addressee = Addressee.for_stream(stream, topic_name)
+
+ do_set_realm_property(realm, "mandatory_topics", True, acting_user=None)
+ realm.refresh_from_db()
+
+ with self.assertRaisesRegex(JsonableError, "Topics are required in this organization"):
+ check_message(sender, client, addressee, message_content, realm)
+
+ do_set_realm_property(realm, "mandatory_topics", False, acting_user=None)
+ realm.refresh_from_db()
+ ret = check_message(sender, client, addressee, message_content, realm)
+ self.assertEqual(ret.message.sender.id, sender.id)