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.

settings: Add move_messages_within_stream_limit_seconds element in UI.

Sahil Batra4378b1639d25
diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js
index e9b81463c22..5917dbb67ab 100644
--- a/frontend_tests/node_tests/settings_org.js
+++ b/frontend_tests/node_tests/settings_org.js
@@ -532,6 +532,9 @@ test("set_up", ({override, override_rewire}) => {
$("#id_realm_message_content_edit_limit_minutes").set_parent(
$.create("<stub edit limit custom input parent>"),
);
+ $("#id_realm_move_messages_within_stream_limit_minutes").set_parent(
+ $.create("<stub move within stream custom input parent>"),
+ );
$("#id_realm_message_content_delete_limit_minutes").set_parent(
$.create("<stub delete limit custom input parent>"),
);
@@ -542,6 +545,11 @@ test("set_up", ({override, override_rewire}) => {
$stub_message_content_edit_limit_parent,
);
+ const $stub_move_within_stream_limit_parent = $.create("<stub move_within_stream_limit parent");
+ $("#id_realm_move_messages_within_stream_limit_seconds").set_parent(
+ $stub_move_within_stream_limit_parent,
+ );
+
const $stub_message_content_delete_limit_parent = $.create(
"<stub message_content_delete_limit parent",
);
@@ -556,6 +564,18 @@ test("set_up", ({override, override_rewire}) => {
);
$custom_edit_limit_input.attr("id", "id_realm_message_content_edit_limit_minutes");
+ const $custom_move_within_stream_limit_input = $(
+ "#id_realm_move_messages_within_stream_limit_minutes",
+ );
+ $stub_move_within_stream_limit_parent.set_find_results(
+ ".time-limit-custom-input",
+ $custom_move_within_stream_limit_input,
+ );
+ $custom_move_within_stream_limit_input.attr(
+ "id",
+ "id_realm_move_messages_within_stream_limit_minutes",
+ );
+
const $custom_delete_limit_input = $("#id_realm_message_content_delete_limit_minutes");
$stub_message_content_delete_limit_parent.set_find_results(
".time-limit-custom-input",
diff --git a/static/js/admin.js b/static/js/admin.js
index ca6a236de62..51b9ce8ac90 100644
--- a/static/js/admin.js
+++ b/static/js/admin.js
@@ -154,6 +154,7 @@ export function build_page() {
admin_settings_label,
msg_edit_limit_dropdown_values: settings_config.msg_edit_limit_dropdown_values,
msg_delete_limit_dropdown_values: settings_config.msg_delete_limit_dropdown_values,
+ msg_move_limit_dropdown_values: settings_config.msg_move_limit_dropdown_values,
bot_creation_policy_values: settings_bots.bot_creation_policy_values,
email_address_visibility_values: settings_config.email_address_visibility_values,
waiting_period_threshold_dropdown_values:
diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js
index f4f3a953c41..f5a2079022a 100644
--- a/static/js/server_events_dispatch.js
+++ b/static/js/server_events_dispatch.js
@@ -211,6 +211,7 @@ export function dispatch_normal_event(event) {
mandatory_topics: noop,
message_content_edit_limit_seconds: noop,
message_content_delete_limit_seconds: noop,
+ move_messages_within_stream_limit_seconds: noop,
message_retention_days: noop,
move_messages_between_streams_policy: noop,
name: notifications.redraw_title,
diff --git a/static/js/settings_config.ts b/static/js/settings_config.ts
index 453b89b5931..02033c3c0e2 100644
--- a/static/js/settings_config.ts
+++ b/static/js/settings_config.ts
@@ -348,6 +348,7 @@ export const time_limit_dropdown_values = [
];
export const msg_edit_limit_dropdown_values = time_limit_dropdown_values;
export const msg_delete_limit_dropdown_values = time_limit_dropdown_values;
+export const msg_move_limit_dropdown_values = time_limit_dropdown_values;
export const waiting_period_threshold_dropdown_values = [
{
diff --git a/static/js/settings_org.js b/static/js/settings_org.js
index 10bfd87af78..b40dcab9768 100644
--- a/static/js/settings_org.js
+++ b/static/js/settings_org.js
@@ -328,6 +328,45 @@ function set_msg_edit_limit_dropdown() {
set_time_limit_setting("realm_message_content_edit_limit_seconds");
}
+function message_move_limit_setting_enabled(related_setting_name) {
+ const setting_value = Number.parseInt($(`#id_${CSS.escape(related_setting_name)}`).val(), 10);
+
+ let settings_options;
+ if (related_setting_name === "realm_edit_topic_policy") {
+ settings_options = settings_config.edit_topic_policy_values;
+ } else {
+ settings_options = settings_config.move_messages_between_streams_policy_values;
+ }
+
+ if (setting_value === settings_options.by_admins_only.code) {
+ return false;
+ }
+
+ if (setting_value === settings_options.by_moderators_only.code) {
+ return false;
+ }
+
+ if (setting_value === settings_options.nobody.code) {
+ return false;
+ }
+
+ return true;
+}
+
+function enable_or_disable_related_message_move_time_limit_setting(setting_name, disable_setting) {
+ const $setting_elem = $(`#id_${CSS.escape(setting_name)}`);
+ const $custom_input_elem = $setting_elem.parent().find(".time-limit-custom-input");
+
+ settings_ui.disable_sub_setting_onchange(disable_setting, $setting_elem.attr("id"), true);
+ settings_ui.disable_sub_setting_onchange(disable_setting, $custom_input_elem.attr("id"), true);
+}
+
+function set_msg_move_limit_setting(property_name) {
+ set_time_limit_setting(property_name);
+ const disable_setting = message_move_limit_setting_enabled("realm_edit_topic_policy");
+ enable_or_disable_related_message_move_time_limit_setting(property_name, disable_setting);
+}
+
function message_delete_limit_setting_enabled(setting_value) {
// This function is used to check whether the time-limit setting
// should be enabled. The setting is disabled when delete_own_message_policy
@@ -633,6 +672,9 @@ export function discard_property_element_changes(elem, for_realm_default_setting
case "realm_message_content_delete_limit_seconds":
set_time_limit_setting(property_name);
break;
+ case "realm_move_messages_within_stream_limit_seconds":
+ set_msg_move_limit_setting(property_name);
+ break;
case "realm_message_retention_days":
case "message_retention_days":
set_message_retention_setting_dropdown(sub);
@@ -886,6 +928,7 @@ export function check_property_changed(elem, for_realm_default_settings, sub) {
break;
case "realm_message_content_edit_limit_seconds":
case "realm_message_content_delete_limit_seconds":
+ case "realm_move_messages_within_stream_limit_seconds":
case "realm_waiting_period_threshold":
proposed_val = get_time_limit_setting_value($elem, false);
break;
@@ -1181,6 +1224,7 @@ export function build_page() {
set_video_chat_provider_dropdown();
set_giphy_rating_dropdown();
set_msg_edit_limit_dropdown();
+ set_msg_move_limit_setting("realm_move_messages_within_stream_limit_seconds");
set_msg_delete_limit_dropdown();
set_delete_own_message_policy_dropdown(page_params.realm_delete_own_message_policy);
set_message_retention_setting_dropdown();
@@ -1206,6 +1250,10 @@ export function build_page() {
update_custom_value_input("realm_message_content_edit_limit_seconds");
});
+ $("#id_realm_move_messages_within_stream_limit_seconds").on("change", () => {
+ update_custom_value_input("realm_move_messages_within_stream_limit_seconds");
+ });
+
$("#id_realm_message_content_delete_limit_seconds").on("change", () => {
update_custom_value_input("realm_message_content_delete_limit_seconds");
});
@@ -1252,6 +1300,18 @@ export function build_page() {
update_message_edit_sub_settings(is_checked);
});
+ $("#org-moving-msgs").on("change", ".move-message-policy-setting", (e) => {
+ const $policy_dropdown_elem = $(e.target);
+ const property_name = extract_property_name($policy_dropdown_elem);
+ const disable_time_limit_setting = message_move_limit_setting_enabled(property_name);
+ const time_limit_setting_name = "realm_move_messages_within_stream_limit_seconds";
+
+ enable_or_disable_related_message_move_time_limit_setting(
+ time_limit_setting_name,
+ disable_time_limit_setting,
+ );
+ });
+
$("#id_realm_delete_own_message_policy").on("change", (e) => {
const setting_value = Number.parseInt($(e.target).val(), 10);
set_delete_own_message_policy_dropdown(setting_value);
diff --git a/static/styles/settings.css b/static/styles/settings.css
index 3b65ccd7522..273d2a7959f 100644
--- a/static/styles/settings.css
+++ b/static/styles/settings.css
@@ -1481,7 +1481,8 @@ $option_title_width: 180px;
#id_realm_edit_topic_policy,
#id_realm_message_content_edit_limit_seconds,
#id_realm_delete_own_message_policy,
-#id_realm_message_content_delete_limit_seconds {
+#id_realm_message_content_delete_limit_seconds,
+#id_realm_move_messages_within_stream_limit_seconds {
width: 325px;
}
diff --git a/static/templates/settings/organization_permissions_admin.hbs b/static/templates/settings/organization_permissions_admin.hbs
index 2538a8a47d2..3eeb3bf303b 100644
--- a/static/templates/settings/organization_permissions_admin.hbs
+++ b/static/templates/settings/organization_permissions_admin.hbs
@@ -191,11 +191,29 @@
</div>
<div class="input-group">
<label for="realm_edit_topic_policy" class="dropdown-title">{{t "Who can move messages to another topic" }}</label>
- <select name="realm_edit_topic_policy" id="id_realm_edit_topic_policy" class="prop-element bootstrap-focus-style" data-setting-widget-type="number">
+ <select name="realm_edit_topic_policy" id="id_realm_edit_topic_policy" class="prop-element move-message-policy-setting bootstrap-focus-style" data-setting-widget-type="number">
{{> dropdown_options_widget option_values=edit_topic_policy_values}}
</select>
</div>
+ <div class="input-group time-limit-setting">
+ <label for="realm_move_messages_within_stream_limit_seconds" class="dropdown-title">{{t "Time limit for editing topics" }} <i>({{t "does not apply to moderators and administrators" }})</i></label>
+ <select name="realm_move_messages_within_stream_limit_seconds" id="id_realm_move_messages_within_stream_limit_seconds" class="prop-element" data-setting-widget-type="time-limit">
+ {{#each msg_move_limit_dropdown_values}}
+ <option value="{{value}}">{{text}}</option>
+ {{/each}}
+ </select>
+ <div class="dependent-settings-block">
+ <label for="id_realm_move_messages_within_stream_limit_minutes" class="inline-block realm-time-limit-label">
+ {{t 'Duration editing is allowed after posting (minutes)'}}:&nbsp;
+ </label>
+ <input type="text" id="id_realm_move_messages_within_stream_limit_minutes"
+ name="realm_move_messages_within_stream_limit_minutes"
+ class="time-limit-custom-input"
+ autocomplete="off"/>
+ </div>
+ </div>
+
<div class="input-group">
<label for="realm_move_messages_between_streams_policy">{{t "Who can move messages to another stream" }}
</label>
diff --git a/tools/lib/capitalization.py b/tools/lib/capitalization.py
index d74c4106436..4eebb8d6060 100644
--- a/tools/lib/capitalization.py
+++ b/tools/lib/capitalization.py
@@ -125,6 +125,8 @@ IGNORED_PHRASES = [
r"he/him",
r"she/her",
r"they/them",
+ # Used in message-move-time-limit setting label
+ r"does not apply to moderators and administrators",
]
# Sort regexes in descending order of their lengths. As a result, the