diff --git a/frontend_tests/node_tests/message_edit.js b/frontend_tests/node_tests/message_edit.js index 9d311f3154..3a4ee0e79d 100644 --- a/frontend_tests/node_tests/message_edit.js +++ b/frontend_tests/node_tests/message_edit.js @@ -124,7 +124,8 @@ run_test("get_editability", ({override}) => { run_test("get_deletability", () => { page_params.is_admin = true; - page_params.realm_allow_message_deleting = false; + page_params.realm_delete_own_message_policy = + settings_config.delete_own_message_policy_values.by_admins_only.code; page_params.realm_message_content_delete_limit_seconds = null; const message = { sent_by_me: false, @@ -145,7 +146,8 @@ run_test("get_deletability", () => { message.locally_echoed = false; assert.equal(message_edit.get_deletability(message), false); - page_params.realm_allow_message_deleting = true; + page_params.realm_delete_own_message_policy = + settings_config.delete_own_message_policy_values.by_everyone.code; assert.equal(message_edit.get_deletability(message), true); const now = new Date(); diff --git a/frontend_tests/node_tests/settings_org.js b/frontend_tests/node_tests/settings_org.js index 353814317e..7e8296185b 100644 --- a/frontend_tests/node_tests/settings_org.js +++ b/frontend_tests/node_tests/settings_org.js @@ -575,7 +575,8 @@ function test_discard_changes_button(discard_changes) { settings_config.common_message_policy_values.by_everyone.code; page_params.realm_allow_message_editing = true; page_params.realm_message_content_edit_limit_seconds = 3600; - page_params.realm_allow_message_deleting = true; + page_params.realm_delete_own_message_policy = + settings_config.delete_own_message_policy_values.by_everyone.code; page_params.realm_message_content_delete_limit_seconds = 120; const allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false); diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 82d38f75e0..cb89279d48 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -28,6 +28,7 @@ import * as overlays from "./overlays"; import {page_params} from "./page_params"; import * as resize from "./resize"; import * as rows from "./rows"; +import * as settings_config from "./settings_config"; import * as settings_data from "./settings_data"; import * as stream_bar from "./stream_bar"; import * as stream_data from "./stream_data"; @@ -167,7 +168,10 @@ export function get_deletability(message) { if (message.locally_echoed) { return false; } - if (!page_params.realm_allow_message_deleting) { + if ( + page_params.realm_delete_own_message_policy === + settings_config.delete_own_message_policy_values.by_admins_only.code + ) { return false; } diff --git a/static/js/server_events_dispatch.js b/static/js/server_events_dispatch.js index 6f4f3a69ad..fb388a2a30 100644 --- a/static/js/server_events_dispatch.js +++ b/static/js/server_events_dispatch.js @@ -183,7 +183,6 @@ export function dispatch_normal_event(event) { const realm_settings = { add_custom_emoji_policy: settings_emoji.update_custom_emoji_ui, allow_edit_history: noop, - allow_message_deleting: noop, allow_message_editing: noop, edit_topic_policy: noop, user_group_edit_policy: noop, @@ -193,6 +192,7 @@ export function dispatch_normal_event(event) { invite_to_stream_policy: noop, default_code_block_language: noop, default_language: noop, + delete_own_message_policy: noop, description: noop, digest_emails_enabled: noop, digest_weekday: noop, diff --git a/static/js/settings_config.ts b/static/js/settings_config.ts index 6ccc2d1797..97363fefc2 100644 --- a/static/js/settings_config.ts +++ b/static/js/settings_config.ts @@ -255,6 +255,19 @@ export const common_message_policy_values = { }, }; +export const delete_own_message_policy_values = { + by_everyone: { + order: 1, + code: 5, + description: $t({defaultMessage: "Admins, members and guests"}), + }, + by_admins_only: { + order: 2, + code: 2, + description: $t({defaultMessage: "Admins only"}), + }, +}; + const time_limit_dropdown_values = new Map([ [ "any_time", @@ -327,7 +340,71 @@ const time_limit_dropdown_values = new Map([ ], ]); 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_delete_limit_dropdown_values = new Map([ + [ + "any_time", + { + text: $t({defaultMessage: "Any time"}), + seconds: 0, + }, + ], + [ + "upto_two_min", + { + text: $t( + {defaultMessage: "Up to {time_limit} after posting"}, + {time_limit: $t({defaultMessage: "2 minutes"})}, + ), + seconds: 2 * 60, + }, + ], + [ + "upto_ten_min", + { + text: $t( + {defaultMessage: "Up to {time_limit} after posting"}, + {time_limit: $t({defaultMessage: "10 minutes"})}, + ), + seconds: 10 * 60, + }, + ], + [ + "upto_one_hour", + { + text: $t( + {defaultMessage: "Up to {time_limit} after posting"}, + {time_limit: $t({defaultMessage: "1 hour"})}, + ), + seconds: 60 * 60, + }, + ], + [ + "upto_one_day", + { + text: $t( + {defaultMessage: "Up to {time_limit} after posting"}, + {time_limit: $t({defaultMessage: "1 day"})}, + ), + seconds: 24 * 60 * 60, + }, + ], + [ + "upto_one_week", + { + text: $t( + {defaultMessage: "Up to {time_limit} after posting"}, + {time_limit: $t({defaultMessage: "1 week"})}, + ), + seconds: 7 * 24 * 60 * 60, + }, + ], + [ + "custom_limit", + { + text: $t({defaultMessage: "Up to N minutes after posting"}), + }, + ], +]); export const retain_message_forever = -1; export const user_role_values = { diff --git a/static/js/settings_org.js b/static/js/settings_org.js index 7bcbf3ea3a..f870a47671 100644 --- a/static/js/settings_org.js +++ b/static/js/settings_org.js @@ -109,6 +109,9 @@ export function get_organization_settings_options() { options.invite_to_realm_policy_values = get_sorted_options_list( settings_config.invite_to_realm_policy_values, ); + options.delete_own_message_policy_values = get_sorted_options_list( + settings_config.delete_own_message_policy_values, + ); return options; } @@ -159,9 +162,6 @@ function get_property_value(property_name) { } if (property_name === "realm_msg_delete_limit_setting") { - if (!page_params.realm_allow_message_deleting) { - return "never"; - } if (page_params.realm_message_content_delete_limit_seconds === null) { return "any_time"; } @@ -249,6 +249,24 @@ function set_msg_edit_limit_dropdown() { settings_ui.disable_sub_setting_onchange(value !== "never", "id_realm_edit_topic_policy", true); } +function set_delete_own_message_policy_dropdown() { + const value = get_property_value("realm_delete_own_message_policy"); + $("#id_realm_delete_own_message_policy").val(value); + settings_ui.disable_sub_setting_onchange( + value !== settings_config.delete_own_message_policy_values.by_admins_only.code, + "id_realm_msg_delete_limit_setting", + true, + ); + const limit_value = get_property_value("realm_msg_delete_limit_setting"); + if (limit_value === "custom_limit") { + settings_ui.disable_sub_setting_onchange( + value !== settings_config.delete_own_message_policy_values.by_admins_only.code, + "id_realm_message_content_delete_limit_minutes", + true, + ); + } +} + function set_msg_delete_limit_dropdown() { const value = get_property_value("realm_msg_delete_limit_setting"); $("#id_realm_msg_delete_limit_setting").val(value); @@ -374,6 +392,9 @@ function update_dependent_subsettings(property_name) { case "realm_message_content_delete_limit_minutes": set_msg_delete_limit_dropdown(); break; + case "realm_delete_own_message_policy": + set_delete_own_message_policy_dropdown(); + break; case "realm_org_join_restrictions": set_org_join_restrictions_dropdown(); break; @@ -457,9 +478,6 @@ export function sync_realm_settings(property) { case "message_content_delete_limit_seconds": property = "message_content_delete_limit_minutes"; break; - case "allow_message_deleting": - property = "msg_delete_limit_setting"; - break; } const element = $(`#id_realm_${CSS.escape(property)}`); if (element.length) { @@ -689,6 +707,7 @@ export function build_page() { set_giphy_rating_dropdown(); set_msg_edit_limit_dropdown(); set_msg_delete_limit_dropdown(); + set_delete_own_message_policy_dropdown(); set_message_retention_setting_dropdown(); set_org_join_restrictions_dropdown(); set_message_content_in_email_notifications_visiblity(); @@ -774,13 +793,7 @@ export function build_page() { } const delete_limit_setting_value = $("#id_realm_msg_delete_limit_setting").val(); switch (delete_limit_setting_value) { - case "never": { - data.allow_message_deleting = false; - - break; - } case "any_time": { - data.allow_message_deleting = true; data.message_content_delete_limit_seconds = JSON.stringify("unlimited"); break; @@ -789,18 +802,17 @@ export function build_page() { data.message_content_delete_limit_seconds = parse_time_limit( $("#id_realm_message_content_delete_limit_minutes"), ); - data.allow_message_deleting = true; break; } default: { - data.allow_message_deleting = true; data.message_content_delete_limit_seconds = settings_config.msg_delete_limit_dropdown_values.get( delete_limit_setting_value, ).seconds; } } + data.delete_own_message_policy = $("#id_realm_delete_own_message_policy").val(); break; } case "notifications": diff --git a/static/styles/settings.css b/static/styles/settings.css index 047a2a2171..25d6e5f18d 100644 --- a/static/styles/settings.css +++ b/static/styles/settings.css @@ -1570,6 +1570,7 @@ input[type="checkbox"] { #id_realm_invite_to_realm_policy, #id_realm_edit_topic_policy, #id_realm_msg_edit_limit_setting, +#id_realm_delete_own_message_policy, #id_realm_msg_delete_limit_setting { width: 325px; } diff --git a/static/templates/settings/organization_permissions_admin.hbs b/static/templates/settings/organization_permissions_admin.hbs index b60d1533b6..91894c011c 100644 --- a/static/templates/settings/organization_permissions_admin.hbs +++ b/static/templates/settings/organization_permissions_admin.hbs @@ -158,11 +158,21 @@ is_checked=realm_allow_edit_history label=admin_settings_label.realm_allow_edit_history}} +
+ + +
+