settings: Add realm-level setting moderation_request_channel.

This commit introduces a new non-operational
`moderation_request_channel` field to the server/API. This setting will
support a feature allowing users to flag or report abusive content
(harassment, spam, etc.).

Fixes part of #20047.
This commit is contained in:
PieterCK
2024-12-03 12:37:27 +07:00
committed by Tim Abbott
parent 238c35f2af
commit 943fbb76fe
14 changed files with 243 additions and 5 deletions

View File

@@ -378,6 +378,13 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
ZULIP_SANDBOX_CHANNEL_NAME = gettext_lazy("sandbox")
DEFAULT_NOTIFICATION_STREAM_NAME = gettext_lazy("general")
STREAM_EVENTS_NOTIFICATION_TOPIC_NAME = gettext_lazy("channel events")
moderation_request_channel = models.ForeignKey(
"Stream",
related_name="+",
null=True,
blank=True,
on_delete=models.SET_NULL,
)
new_stream_announcements_stream = models.ForeignKey(
"Stream",
related_name="+",
@@ -911,6 +918,14 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
def get_bot_domain(self) -> str:
return get_fake_email_domain(self.host)
def get_moderation_request_channel(self) -> Optional["Stream"]:
if (
self.moderation_request_channel is not None
and not self.moderation_request_channel.deactivated
):
return self.moderation_request_channel
return None
def get_new_stream_announcements_stream(self) -> Optional["Stream"]:
if (
self.new_stream_announcements_stream is not None
@@ -1148,6 +1163,7 @@ def get_realm_with_settings(realm_id: int) -> Realm:
# * All the settings that can be set to anonymous groups.
# * Announcements streams.
return Realm.objects.select_related(
"moderation_request_channel",
"create_multiuse_invite_group",
"create_multiuse_invite_group__named_user_group",
"can_access_all_users_group",