settings: Add a new topics_policy realm setting.

Added a new realm setting, `topics_policy` and deprecated
`mandatory_topics` setting as it now replaced by `topics_policy`.

Fixes part of #33549.
This commit is contained in:
Vector73
2025-06-14 11:19:57 +00:00
committed by Tim Abbott
parent 8fb1eeeb09
commit 62c67eae8e
38 changed files with 313 additions and 57 deletions

View File

@@ -90,6 +90,7 @@ from zerver.models import (
UserProfile,
UserTopic,
)
from zerver.models.realms import RealmTopicsPolicyEnum
from zerver.models.streams import get_stream_by_id_in_realm
from zerver.models.users import ResolvedTopicNoticeAutoReadPolicyEnum, get_system_bot
from zerver.tornado.django_api import send_event_on_commit
@@ -128,7 +129,10 @@ def validate_message_edit_payload(
if propagate_mode != "change_one" and topic_name is None and stream_id is None:
raise JsonableError(_("Invalid propagate_mode without topic edit"))
if message.realm.mandatory_topics and topic_name in ("(no topic)", ""):
if (
message.realm.topics_policy == RealmTopicsPolicyEnum.disable_empty_topic.value
and topic_name in ("(no topic)", "")
):
raise JsonableError(_("Topics are required in this organization."))
if topic_name in {