Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
streams: Remove stream_post_policy field from Stream.
Sahil Batrab4b571d60c09
diff --git a/zerver/data_import/import_util.py b/zerver/data_import/import_util.pyindex d73116e8eb4..62c3061d264 100644--- a/zerver/data_import/import_util.py+++ b/zerver/data_import/import_util.py@@ -470,10 +470,10 @@ def build_stream(date_created=date_created,invite_only=invite_only,id=stream_id,- stream_post_policy=stream_post_policy,history_public_to_subscribers=history_public_to_subscribers,)stream_dict = model_to_dict(stream, exclude=["realm"])+ stream_dict["stream_post_policy"] = stream_post_policystream_dict["realm"] = realm_idreturn stream_dictdiff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.pyindex d763f47f42d..fb032e0a11d 100644--- a/zerver/lib/import_realm.py+++ b/zerver/lib/import_realm.py@@ -253,16 +253,23 @@ def fix_stream_permission_group_settings(table = get_db_table(Stream)for stream in data[table]:for setting_name in Stream.stream_permission_group_settings:- if (- setting_name == "can_send_message_group"- and stream["stream_post_policy"] == Stream.STREAM_POST_POLICY_MODERATORS- ):+ if setting_name == "can_send_message_group" and "stream_post_policy" in stream:# This block is needed when importing data for Rocket.Chat.# While converting the data into Zulip supported format,# stream_post_policy for read-only Rocket.Chat channel is# set to STREAM_POST_POLICY_MODERATORS and so we need to# set the can_send_message_group setting accordingly.- stream[setting_name] = system_groups_name_dict[SystemGroups.MODERATORS]+ if stream["stream_post_policy"] == Stream.STREAM_POST_POLICY_MODERATORS:+ stream[setting_name] = system_groups_name_dict[SystemGroups.MODERATORS]+ else:+ stream[setting_name] = get_stream_permission_default_group(+ setting_name, system_groups_name_dict+ )++ # Delete the stream_post_policy once can_send_message_group+ # field is set correctly.+ del stream["stream_post_policy"]+continuestream[setting_name] = get_stream_permission_default_group(diff --git a/zerver/lib/streams.py b/zerver/lib/streams.pyindex de71b93e7dd..bda4f7b74fe 100644--- a/zerver/lib/streams.py+++ b/zerver/lib/streams.py@@ -183,7 +183,6 @@ def create_stream_if_needed(*,invite_only: bool = False,is_web_public: bool = False,- stream_post_policy: int = Stream.STREAM_POST_POLICY_EVERYONE,history_public_to_subscribers: bool | None = None,stream_description: str = "",message_retention_days: int | None = None,@@ -226,7 +225,6 @@ def create_stream_if_needed(description=stream_description,invite_only=invite_only,is_web_public=is_web_public,- stream_post_policy=stream_post_policy,history_public_to_subscribers=history_public_to_subscribers,is_in_zephyr_realm=realm.is_zephyr_mirror_realm,message_retention_days=message_retention_days,@@ -287,9 +285,6 @@ def create_streams_if_needed(stream_dict["name"],invite_only=invite_only,is_web_public=stream_dict.get("is_web_public", False),- stream_post_policy=stream_dict.get(- "stream_post_policy", Stream.STREAM_POST_POLICY_EVERYONE- ),history_public_to_subscribers=stream_dict.get("history_public_to_subscribers"),stream_description=stream_dict.get("description", ""),message_retention_days=stream_dict.get("message_retention_days", None),diff --git a/zerver/migrations/0648_remove_stream_stream_post_policy.py b/zerver/migrations/0648_remove_stream_stream_post_policy.pynew file mode 100644index 00000000000..a9f887c4407--- /dev/null+++ b/zerver/migrations/0648_remove_stream_stream_post_policy.py@@ -0,0 +1,16 @@+# Generated by Django 5.0.9 on 2024-12-18 09:24++from django.db import migrations+++class Migration(migrations.Migration):+ dependencies = [+ ("zerver", "0647_alter_stream_can_send_message_group"),+ ]++ operations = [+ migrations.RemoveField(+ model_name="stream",+ name="stream_post_policy",+ ),+ ]diff --git a/zerver/models/streams.py b/zerver/models/streams.pyindex ebe90912679..da313bf49d3 100644--- a/zerver/models/streams.py+++ b/zerver/models/streams.py@@ -7,7 +7,6 @@ from django.db.models.functions import Upperfrom django.db.models.signals import post_delete, post_savefrom django.utils.timezone import now as timezone_nowfrom django.utils.translation import gettext_lazy-from django_stubs_ext import StrPromisefrom typing_extensions import overridefrom zerver.lib.cache import flush_stream@@ -78,27 +77,21 @@ class Stream(models.Model):# Whether this stream's content should be published by the web-public archive featuresis_web_public = models.BooleanField(default=False)+ # These values are used to map the can_send_message_group setting value+ # to the corresponding stream_post_policy value for legacy API clients+ # in get_stream_post_policy_value_based_on_group_setting defined in+ # zerver/lib/streams.py.STREAM_POST_POLICY_EVERYONE = 1STREAM_POST_POLICY_ADMINS = 2STREAM_POST_POLICY_RESTRICT_NEW_MEMBERS = 3STREAM_POST_POLICY_MODERATORS = 4- # TODO: Implement policy to restrict posting to a user group or admins.-- # Who in the organization has permission to send messages to this stream.- stream_post_policy = models.PositiveSmallIntegerField(default=STREAM_POST_POLICY_EVERYONE)- POST_POLICIES: dict[int, StrPromise] = {- # These strings should match the strings in the- # stream_post_policy_values object in stream_data.js.- STREAM_POST_POLICY_EVERYONE: gettext_lazy("All channel members can post"),- STREAM_POST_POLICY_ADMINS: gettext_lazy("Only organization administrators can post"),- STREAM_POST_POLICY_MODERATORS: gettext_lazy(- "Only organization administrators and moderators can post"- ),- STREAM_POST_POLICY_RESTRICT_NEW_MEMBERS: gettext_lazy(- "Only organization full members can post"- ),- }- STREAM_POST_POLICY_TYPES = list(POST_POLICIES.keys())++ STREAM_POST_POLICY_TYPES = [+ STREAM_POST_POLICY_EVERYONE,+ STREAM_POST_POLICY_ADMINS,+ STREAM_POST_POLICY_RESTRICT_NEW_MEMBERS,+ STREAM_POST_POLICY_MODERATORS,+ ]SYSTEM_GROUPS_ENUM_MAP = {SystemGroups.EVERYONE: STREAM_POST_POLICY_EVERYONE,@@ -212,7 +205,6 @@ class Stream(models.Model):"message_retention_days","name","rendered_description",- "stream_post_policy","can_administer_channel_group_id","can_send_message_group_id","can_remove_subscribers_group_id",diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.pyindex 78cbe06bf73..e55a49c4c90 100644--- a/zerver/tests/test_subs.py+++ b/zerver/tests/test_subs.py@@ -253,7 +253,12 @@ class TestMiscStuff(ZulipTestCase):expected_fields = fix_expected_fields_for_stream_group_settings(expected_fields)stream_dict_fields = set(APIStreamDict.__annotations__.keys())- computed_fields = {"is_announcement_only", "is_default", "stream_weekly_traffic"}+ computed_fields = {+ "is_announcement_only",+ "is_default",+ "stream_post_policy",+ "stream_weekly_traffic",+ }self.assertEqual(stream_dict_fields - computed_fields, expected_fields)@@ -309,7 +314,6 @@ class TestCreateStreams(ZulipTestCase):"name": stream_name,"description": stream_description,"invite_only": True,- "stream_post_policy": Stream.STREAM_POST_POLICY_ADMINS,"message_retention_days": -1,"can_remove_subscribers_group": moderators_system_group,}@@ -328,7 +332,6 @@ class TestCreateStreams(ZulipTestCase):self.assertEqual(actual_stream_descriptions, set(stream_descriptions))for stream in new_streams:self.assertTrue(stream.invite_only)- self.assertTrue(stream.stream_post_policy == Stream.STREAM_POST_POLICY_ADMINS)self.assertTrue(stream.message_retention_days == -1)self.assertEqual(stream.can_remove_subscribers_group.id, moderators_system_group.id)# Streams created where acting_user is None have no creator@@ -742,7 +745,6 @@ class TestCreateStreams(ZulipTestCase):description="No description",invite_only=True,is_web_public=True,- stream_post_policy=Stream.STREAM_POST_POLICY_ADMINS,)],acting_user=hamlet,@@ -6321,6 +6323,7 @@ class GetSubscribersTest(ZulipTestCase):"is_announcement_only","in_home_view","stream_id",+ "stream_post_policy","stream_weekly_traffic","subscribers",}@@ -6337,6 +6340,7 @@ class GetSubscribersTest(ZulipTestCase):"is_archived","is_announcement_only","stream_id",+ "stream_post_policy","stream_weekly_traffic","subscribers",}