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.

realm: Add time limit setting for moving message within stream.

Sahil Batra73f0eae39474
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index 9126b993a5f..c64a173a1f3 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,11 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 7.0
+**Feature level 162**
+
+* [`POST /register`](/api/register-queue), [`GET /events`](/api/get-events),
+ `PATCH /realm`: Added new `move_messages_within_stream_limit_seconds` setting.
+
**Feature level 161**
* [`PATCH /streams/{stream_id}`](/api/update-stream): Added
diff --git a/zerver/migrations/0424_realm_move_messages_within_stream_limit_seconds.py b/zerver/migrations/0424_realm_move_messages_within_stream_limit_seconds.py
new file mode 100644
index 00000000000..94d8cccd284
--- /dev/null
+++ b/zerver/migrations/0424_realm_move_messages_within_stream_limit_seconds.py
@@ -0,0 +1,17 @@
+# Generated by Django 4.1.5 on 2023-01-26 14:27
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("zerver", "0423_fix_email_gateway_attachment_owner"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="realm",
+ name="move_messages_within_stream_limit_seconds",
+ field=models.PositiveIntegerField(default=604800, null=True),
+ ),
+ ]
diff --git a/zerver/models.py b/zerver/models.py
index fd7e1fd6e2f..fb1d767f750 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -115,6 +115,8 @@ from zerver.lib.validator import (
MAX_TOPIC_NAME_LENGTH = 60
MAX_LANGUAGE_ID_LENGTH: int = 50
+SECONDS_PER_DAY = 86400
+
STREAM_NAMES = TypeVar("STREAM_NAMES", Sequence[str], AbstractSet[str])
if TYPE_CHECKING:
@@ -379,6 +381,12 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
DEFAULT_COMMUNITY_TOPIC_EDITING_LIMIT_SECONDS = 259200
+ DEFAULT_MOVE_MESSAGE_LIMIT_SECONDS = 7 * SECONDS_PER_DAY
+
+ move_messages_within_stream_limit_seconds = models.PositiveIntegerField(
+ default=DEFAULT_MOVE_MESSAGE_LIMIT_SECONDS, null=True
+ )
+
# Who in the organization is allowed to add custom emojis.
add_custom_emoji_policy = models.PositiveSmallIntegerField(default=POLICY_MEMBERS_ONLY)
@@ -728,6 +736,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
message_content_allowed_in_email_notifications=bool,
message_content_edit_limit_seconds=(int, type(None)),
message_content_delete_limit_seconds=(int, type(None)),
+ move_messages_within_stream_limit_seconds=(int, type(None)),
message_retention_days=(int, type(None)),
move_messages_between_streams_policy=int,
name=str,
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index 0520d84ae62..047c440aa0d 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -4032,6 +4032,20 @@ paths:
**Changes**: No limit was represented using the
special value `0` before Zulip 6.0 (feature level 138).
+ move_messages_within_stream_limit_seconds:
+ type: integer
+ nullable: true
+ description: |
+ Messages sent more than this many seconds ago cannot be moved within a
+ stream by members with this organization's [message move
+ policy](/help/configure-who-can-edit-topics). This setting does not
+ affect moderators and administrators.
+
+ Will not be 0. A 'null' value means no limit: messages can be moved
+ regardless of how long ago they were sent.
+
+ **Changes**: New in Zulip 7.0 (feature level 162). Previously, this
+ limit was always 72 hours.
move_messages_between_streams_policy:
type: integer
description: |
@@ -12202,6 +12216,22 @@ paths:
**Changes**: No limit was represented using the
special value `0` before Zulip 6.0 (feature level 138).
+ realm_move_messages_within_stream_limit_seconds:
+ type: integer
+ nullable: true
+ description: |
+ Present if `realm` is present in `fetch_event_types`.
+
+ Messages sent more than this many seconds ago cannot be moved within a
+ stream by members with this organization's [message move
+ policy](/help/configure-who-can-edit-topics). This setting does not
+ affect moderators and administrators.
+
+ Will not be 0. A 'null' value means no limit: messages can be moved
+ regardless of how long ago they were sent.
+
+ **Changes**: New in Zulip 7.0 (feature level 162). Previously, this
+ limit was always 72 hours.
realm_community_topic_editing_limit_seconds:
type: integer
description: |
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 49c32438629..48c10ebd2f7 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -2604,6 +2604,7 @@ class RealmPropertyActionTest(BaseAction):
delete_own_message_policy=Realm.COMMON_MESSAGE_POLICY_TYPES,
edit_topic_policy=Realm.COMMON_MESSAGE_POLICY_TYPES,
message_content_edit_limit_seconds=[1000, 1100, 1200, None],
+ move_messages_within_stream_limit_seconds=[1000, 1100, 1200],
)
vals = test_values.get(name)
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index ea3d5347f25..c6371e0aeeb 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -160,6 +160,7 @@ class HomeTest(ZulipTestCase):
"realm_message_content_edit_limit_seconds",
"realm_message_retention_days",
"realm_move_messages_between_streams_policy",
+ "realm_move_messages_within_stream_limit_seconds",
"realm_name",
"realm_name_changes_disabled",
"realm_night_logo_source",
diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py
index bcf5c472fcb..46c7efe1f99 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -639,6 +639,7 @@ class RealmTest(ZulipTestCase):
delete_own_message_policy=10,
edit_topic_policy=10,
message_content_edit_limit_seconds=0,
+ move_messages_within_stream_limit_seconds=0,
)
# We need an admin user.
@@ -1176,6 +1177,7 @@ class RealmAPITest(ZulipTestCase):
delete_own_message_policy=Realm.COMMON_MESSAGE_POLICY_TYPES,
edit_topic_policy=Realm.EDIT_TOPIC_POLICY_TYPES,
message_content_edit_limit_seconds=[1000, 1100, 1200],
+ move_messages_within_stream_limit_seconds=[1000, 1100, 1200],
)
vals = test_values.get(name)
@@ -1316,6 +1318,14 @@ class RealmAPITest(ZulipTestCase):
self.assertIn("ignored_parameters_unsupported", result)
self.assertEqual(result["ignored_parameters_unsupported"], ["emoji_set"])
+ def test_update_realm_move_messages_within_stream_limit_seconds_unlimited_value(self) -> None:
+ realm = get_realm("zulip")
+ self.login("iago")
+ realm = self.update_with_api(
+ "move_messages_within_stream_limit_seconds", orjson.dumps("unlimited").decode()
+ )
+ self.assertEqual(realm.move_messages_within_stream_limit_seconds, None)
+
def test_update_realm_delete_own_message_policy(self) -> None:
"""Tests updating the realm property 'delete_own_message_policy'."""
self.set_up_db("delete_own_message_policy", Realm.POLICY_EVERYONE)
diff --git a/zerver/views/realm.py b/zerver/views/realm.py
index 2e089aa6a4d..7250515cec8 100644
--- a/zerver/views/realm.py
+++ b/zerver/views/realm.py
@@ -146,6 +146,11 @@ def update_realm(
json_validator=check_bool, default=None
),
enable_read_receipts: Optional[bool] = REQ(json_validator=check_bool, default=None),
+ move_messages_within_stream_limit_seconds_raw: Optional[Union[int, str]] = REQ(
+ "move_messages_within_stream_limit_seconds",
+ json_validator=check_string_or_int,
+ default=None,
+ ),
) -> HttpResponse:
realm = user_profile.realm
@@ -225,6 +230,23 @@ def update_realm(
if setting_value_changed:
data["message_content_edit_limit_seconds"] = message_content_edit_limit_seconds
+ move_messages_within_stream_limit_seconds: Optional[int] = None
+ if move_messages_within_stream_limit_seconds_raw is not None:
+ (
+ move_messages_within_stream_limit_seconds,
+ setting_value_changed,
+ ) = parse_and_set_setting_value_if_required(
+ realm,
+ "move_messages_within_stream_limit_seconds",
+ move_messages_within_stream_limit_seconds_raw,
+ acting_user=user_profile,
+ )
+
+ if setting_value_changed:
+ data[
+ "move_messages_within_stream_limit_seconds"
+ ] = move_messages_within_stream_limit_seconds
+
# The user of `locals()` here is a bit of a code smell, but it's
# restricted to the elements present in realm.property_types.
#