2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
import pygments_data from "../generated/pygments_data.json";
|
2021-06-21 10:52:02 +02:00
|
|
|
import render_settings_deactivate_realm_modal from "../templates/confirm_dialog/confirm_deactivate_realm.hbs";
|
2021-02-28 01:20:46 +01:00
|
|
|
import render_settings_admin_auth_methods_list from "../templates/settings/admin_auth_methods_list.hbs";
|
|
|
|
import render_settings_admin_realm_domains_list from "../templates/settings/admin_realm_domains_list.hbs";
|
|
|
|
|
2021-03-16 23:38:59 +01:00
|
|
|
import * as blueslip from "./blueslip";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as channel from "./channel";
|
2021-05-26 19:31:13 +02:00
|
|
|
import * as confirm_dialog from "./confirm_dialog";
|
2021-03-25 23:20:18 +01:00
|
|
|
import {csrf_token} from "./csrf";
|
2021-07-27 14:05:22 +02:00
|
|
|
import {DropdownListWidget} from "./dropdown_list_widget";
|
2021-04-13 06:51:54 +02:00
|
|
|
import {$t, $t_html} from "./i18n";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as loading from "./loading";
|
|
|
|
import * as overlays from "./overlays";
|
2021-03-25 22:35:45 +01:00
|
|
|
import {page_params} from "./page_params";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as realm_icon from "./realm_icon";
|
|
|
|
import * as realm_logo from "./realm_logo";
|
|
|
|
import * as settings_config from "./settings_config";
|
|
|
|
import * as settings_notifications from "./settings_notifications";
|
2021-09-30 12:00:57 +02:00
|
|
|
import * as settings_realm_user_settings_defaults from "./settings_realm_user_settings_defaults";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as settings_ui from "./settings_ui";
|
2021-04-04 15:15:18 +02:00
|
|
|
import * as stream_settings_data from "./stream_settings_data";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
|
|
|
|
|
|
|
export let parse_time_limit;
|
|
|
|
export let save_organization_settings;
|
2019-07-09 21:24:00 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const meta = {
|
2017-04-08 18:13:39 +02:00
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function reset() {
|
2017-04-17 16:51:27 +02:00
|
|
|
meta.loaded = false;
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2017-04-17 16:51:27 +02:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function maybe_disable_widgets() {
|
2020-06-11 13:26:27 +02:00
|
|
|
if (page_params.is_owner) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-11 16:24:15 +02:00
|
|
|
$(".organization-box [data-name='auth-methods']")
|
2020-07-15 00:34:28 +02:00
|
|
|
.find("input, button, select, checked")
|
2020-07-22 02:59:06 +02:00
|
|
|
.prop("disabled", true);
|
2020-06-11 16:24:15 +02:00
|
|
|
|
2018-12-08 17:37:57 +01:00
|
|
|
if (page_params.is_admin) {
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#deactivate_realm_button").prop("disabled", true);
|
|
|
|
$("#org-message-retention").find("input, select").prop("disabled", true);
|
2021-07-19 11:47:42 +02:00
|
|
|
$("#id_realm_invite_to_realm_policy").prop("disabled", true);
|
2018-12-08 17:37:57 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-profile']")
|
2020-07-15 00:34:28 +02:00
|
|
|
.find("input, textarea, button, select")
|
2020-07-22 02:59:06 +02:00
|
|
|
.prop("disabled", true);
|
2018-12-08 17:37:57 +01:00
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-settings']")
|
2020-07-15 00:34:28 +02:00
|
|
|
.find("input, textarea, button, select")
|
2020-07-22 02:59:06 +02:00
|
|
|
.prop("disabled", true);
|
2018-12-08 17:37:57 +01:00
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-settings']")
|
2020-07-15 00:34:28 +02:00
|
|
|
.find(".control-label-disabled")
|
|
|
|
.addClass("enabled");
|
2018-12-08 17:37:57 +01:00
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-permissions']")
|
2020-07-15 00:34:28 +02:00
|
|
|
.find("input, textarea, button, select")
|
2020-07-22 02:59:06 +02:00
|
|
|
.prop("disabled", true);
|
2018-12-08 17:37:57 +01:00
|
|
|
|
|
|
|
$(".organization-box [data-name='organization-permissions']")
|
2020-07-15 00:34:28 +02:00
|
|
|
.find(".control-label-disabled")
|
|
|
|
.addClass("enabled");
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2018-12-08 17:37:57 +01:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function get_sorted_options_list(option_values_object) {
|
2020-07-02 01:39:34 +02:00
|
|
|
const options_list = Object.keys(option_values_object).map((key) => ({
|
2020-02-09 04:15:38 +01:00
|
|
|
...option_values_object[key],
|
2020-07-20 22:18:43 +02:00
|
|
|
key,
|
2020-02-09 04:15:38 +01:00
|
|
|
}));
|
2020-01-23 07:01:34 +01:00
|
|
|
let comparator = (x, y) => x.order - y.order;
|
|
|
|
if (!options_list[0].order) {
|
|
|
|
comparator = (x, y) => {
|
|
|
|
const key_x = x.key.toUpperCase();
|
|
|
|
const key_y = y.key.toUpperCase();
|
|
|
|
if (key_x < key_y) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (key_x > key_y) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
options_list.sort(comparator);
|
|
|
|
return options_list;
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2020-01-23 07:01:34 +01:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function get_organization_settings_options() {
|
2020-01-23 07:01:34 +01:00
|
|
|
const options = {};
|
2021-04-28 20:39:24 +02:00
|
|
|
options.common_policy_values = get_sorted_options_list(settings_config.common_policy_values);
|
2021-02-28 01:20:46 +01:00
|
|
|
options.private_message_policy_values = get_sorted_options_list(
|
2020-07-15 00:34:28 +02:00
|
|
|
settings_config.private_message_policy_values,
|
|
|
|
);
|
2021-02-28 01:20:46 +01:00
|
|
|
options.wildcard_mention_policy_values = get_sorted_options_list(
|
2020-09-14 19:26:42 +02:00
|
|
|
settings_config.wildcard_mention_policy_values,
|
|
|
|
);
|
2021-05-26 12:21:37 +02:00
|
|
|
options.common_message_policy_values = get_sorted_options_list(
|
|
|
|
settings_config.common_message_policy_values,
|
|
|
|
);
|
2021-07-18 18:18:28 +02:00
|
|
|
options.invite_to_realm_policy_values = get_sorted_options_list(
|
|
|
|
settings_config.invite_to_realm_policy_values,
|
|
|
|
);
|
2020-01-23 07:01:34 +01:00
|
|
|
return options;
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2020-01-23 07:01:34 +01:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function get_realm_time_limits_in_minutes(property) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let val = (page_params[property] / 60).toFixed(1);
|
2020-10-07 09:17:30 +02:00
|
|
|
if (Number.parseFloat(val, 10) === Number.parseInt(val, 10)) {
|
|
|
|
val = Number.parseInt(val, 10);
|
2018-04-28 15:35:14 +02:00
|
|
|
}
|
|
|
|
return val.toString();
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2018-04-28 15:35:14 +02:00
|
|
|
|
2018-04-01 08:56:18 +02:00
|
|
|
function get_property_value(property_name) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (property_name === "realm_message_content_edit_limit_minutes") {
|
2021-02-28 01:20:46 +01:00
|
|
|
return get_realm_time_limits_in_minutes("realm_message_content_edit_limit_seconds");
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (property_name === "realm_message_content_delete_limit_minutes") {
|
2021-02-28 01:20:46 +01:00
|
|
|
return get_realm_time_limits_in_minutes("realm_message_content_delete_limit_seconds");
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (property_name === "realm_waiting_period_setting") {
|
2019-05-07 19:06:05 +02:00
|
|
|
if (page_params.realm_waiting_period_threshold === 0) {
|
|
|
|
return "none";
|
|
|
|
}
|
|
|
|
if (page_params.realm_waiting_period_threshold === 3) {
|
|
|
|
return "three_days";
|
|
|
|
}
|
|
|
|
return "custom_days";
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (property_name === "realm_msg_edit_limit_setting") {
|
2018-04-02 11:18:40 +02:00
|
|
|
if (!page_params.realm_allow_message_editing) {
|
|
|
|
return "never";
|
|
|
|
}
|
2020-02-09 05:23:25 +01:00
|
|
|
for (const [value, elem] of settings_config.msg_edit_limit_dropdown_values) {
|
|
|
|
if (elem.seconds === page_params.realm_message_content_edit_limit_seconds) {
|
|
|
|
return value;
|
|
|
|
}
|
2018-04-02 11:18:40 +02:00
|
|
|
}
|
2020-02-09 05:23:25 +01:00
|
|
|
return "custom_limit";
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (property_name === "realm_message_retention_setting") {
|
2020-06-25 23:44:45 +02:00
|
|
|
if (page_params.realm_message_retention_days === settings_config.retain_message_forever) {
|
2020-05-07 13:19:54 +02:00
|
|
|
return "retain_forever";
|
|
|
|
}
|
|
|
|
return "retain_for_period";
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (property_name === "realm_msg_delete_limit_setting") {
|
2021-06-14 18:49:28 +02:00
|
|
|
if (page_params.realm_message_content_delete_limit_seconds === null) {
|
|
|
|
return "any_time";
|
|
|
|
}
|
2020-02-09 05:23:25 +01:00
|
|
|
for (const [value, elem] of settings_config.msg_delete_limit_dropdown_values) {
|
|
|
|
if (elem.seconds === page_params.realm_message_content_delete_limit_seconds) {
|
|
|
|
return value;
|
|
|
|
}
|
2017-11-26 09:12:10 +01:00
|
|
|
}
|
2020-02-09 05:23:25 +01:00
|
|
|
return "custom_limit";
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
if (property_name === "realm_org_join_restrictions") {
|
2018-07-27 23:26:29 +02:00
|
|
|
if (page_params.realm_emails_restricted_to_domains) {
|
2018-04-05 00:54:31 +02:00
|
|
|
return "only_selected_domain";
|
|
|
|
}
|
|
|
|
if (page_params.realm_disallow_disposable_email_addresses) {
|
|
|
|
return "no_disposable_email";
|
|
|
|
}
|
|
|
|
return "no_restriction";
|
2018-06-16 13:27:56 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 21:45:47 +02:00
|
|
|
return page_params[property_name];
|
2018-03-29 12:52:57 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function extract_property_name(elem) {
|
2020-07-15 01:29:15 +02:00
|
|
|
return elem.attr("id").split("-").join("_").replace("id_", "");
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2018-03-29 12:52:57 +02:00
|
|
|
|
2019-05-05 22:37:09 +02:00
|
|
|
function get_subsection_property_elements(element) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const subsection = $(element).closest(".org-subsection-parent");
|
|
|
|
return Array.from(subsection.find(".prop-element"));
|
2019-05-05 22:37:09 +02:00
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const simple_dropdown_properties = [
|
2021-03-27 05:48:37 +01:00
|
|
|
"realm_create_private_stream_policy",
|
|
|
|
"realm_create_public_stream_policy",
|
2020-07-15 00:34:28 +02:00
|
|
|
"realm_invite_to_stream_policy",
|
|
|
|
"realm_user_group_edit_policy",
|
|
|
|
"realm_private_message_policy",
|
2021-05-04 19:02:24 +02:00
|
|
|
"realm_add_custom_emoji_policy",
|
2021-05-23 21:40:20 +02:00
|
|
|
"realm_invite_to_realm_policy",
|
2020-09-14 19:26:42 +02:00
|
|
|
"realm_wildcard_mention_policy",
|
2021-04-30 09:35:20 +02:00
|
|
|
"realm_move_messages_between_streams_policy",
|
2021-05-26 12:21:37 +02:00
|
|
|
"realm_edit_topic_policy",
|
2020-07-15 00:34:28 +02:00
|
|
|
];
|
2020-02-03 12:40:36 +01:00
|
|
|
|
|
|
|
function set_property_dropdown_value(property_name) {
|
2021-02-03 23:23:32 +01:00
|
|
|
$(`#id_${CSS.escape(property_name)}`).val(get_property_value(property_name));
|
2020-02-03 12:40:36 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 13:03:53 +01:00
|
|
|
function change_element_block_display_property(elem_id, show_element) {
|
2021-02-03 23:23:32 +01:00
|
|
|
const elem = $(`#${CSS.escape(elem_id)}`);
|
2020-02-03 13:03:53 +01:00
|
|
|
if (show_element) {
|
|
|
|
elem.parent().show();
|
|
|
|
} else {
|
|
|
|
elem.parent().hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
function set_realm_waiting_period_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_waiting_period_setting");
|
2019-05-07 19:06:05 +02:00
|
|
|
$("#id_realm_waiting_period_setting").val(value);
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_waiting_period_threshold",
|
|
|
|
value === "custom_days",
|
|
|
|
);
|
2018-04-01 08:49:10 +02:00
|
|
|
}
|
2018-01-05 15:34:10 +01:00
|
|
|
|
2018-04-23 14:51:30 +02:00
|
|
|
function set_video_chat_provider_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const chat_provider_id = page_params.realm_video_chat_provider;
|
2019-05-09 09:54:38 +02:00
|
|
|
$("#id_realm_video_chat_provider").val(chat_provider_id);
|
2018-04-23 14:51:30 +02:00
|
|
|
}
|
|
|
|
|
2021-04-27 21:58:19 +02:00
|
|
|
function set_giphy_rating_dropdown() {
|
|
|
|
const rating_id = page_params.realm_giphy_rating;
|
|
|
|
$("#id_realm_giphy_rating").val(rating_id);
|
|
|
|
}
|
|
|
|
|
2018-04-02 11:18:40 +02:00
|
|
|
function set_msg_edit_limit_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_msg_edit_limit_setting");
|
2018-04-02 11:18:40 +02:00
|
|
|
$("#id_realm_msg_edit_limit_setting").val(value);
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_message_content_edit_limit_minutes",
|
|
|
|
value === "custom_limit",
|
|
|
|
);
|
2021-05-26 12:21:37 +02:00
|
|
|
settings_ui.disable_sub_setting_onchange(value !== "never", "id_realm_edit_topic_policy", true);
|
2018-04-02 11:18:40 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 12:53:38 +02:00
|
|
|
function message_delete_limit_setting_enabled() {
|
|
|
|
// This function is used to check whether the time-limit setting
|
|
|
|
// should be enabled. The setting is disabled when delete_own_message_policy
|
|
|
|
// is set to 'admins only' as admins can delete messages irrespective of
|
|
|
|
// time limit.
|
|
|
|
if (
|
|
|
|
page_params.realm_delete_own_message_policy ===
|
|
|
|
settings_config.common_message_policy_values.by_admins_only.code
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-08 13:45:14 +02:00
|
|
|
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(
|
2021-06-23 12:53:38 +02:00
|
|
|
message_delete_limit_setting_enabled(),
|
2021-06-08 13:45:14 +02:00
|
|
|
"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(
|
2021-06-23 12:53:38 +02:00
|
|
|
message_delete_limit_setting_enabled(),
|
2021-06-08 13:45:14 +02:00
|
|
|
"id_realm_message_content_delete_limit_minutes",
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-26 09:12:10 +01:00
|
|
|
function set_msg_delete_limit_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_msg_delete_limit_setting");
|
2017-11-26 09:12:10 +01:00
|
|
|
$("#id_realm_msg_delete_limit_setting").val(value);
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_message_content_delete_limit_minutes",
|
|
|
|
value === "custom_limit",
|
|
|
|
);
|
2017-11-26 09:12:10 +01:00
|
|
|
}
|
|
|
|
|
2020-05-07 13:19:54 +02:00
|
|
|
function set_message_retention_setting_dropdown() {
|
|
|
|
const value = get_property_value("realm_message_retention_setting");
|
|
|
|
$("#id_realm_message_retention_setting").val(value);
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_message_retention_days",
|
|
|
|
value === "retain_for_period",
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
get_property_value("realm_message_retention_days") ===
|
|
|
|
settings_config.retain_message_forever
|
|
|
|
) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#id_realm_message_retention_days").val("");
|
2020-06-21 11:35:02 +02:00
|
|
|
}
|
2020-05-07 13:19:54 +02:00
|
|
|
}
|
|
|
|
|
2018-04-05 00:54:31 +02:00
|
|
|
function set_org_join_restrictions_dropdown() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const value = get_property_value("realm_org_join_restrictions");
|
2018-04-05 00:54:31 +02:00
|
|
|
$("#id_realm_org_join_restrictions").val(value);
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"allowed_domains_label",
|
|
|
|
value === "only_selected_domain",
|
|
|
|
);
|
2018-04-05 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
2019-01-14 14:04:08 +01:00
|
|
|
function set_message_content_in_email_notifications_visiblity() {
|
2020-02-03 13:03:53 +01:00
|
|
|
change_element_block_display_property(
|
2020-07-15 01:29:15 +02:00
|
|
|
"message_content_in_email_notifications_label",
|
2020-07-15 00:34:28 +02:00
|
|
|
page_params.realm_message_content_allowed_in_email_notifications,
|
|
|
|
);
|
2019-01-14 14:04:08 +01:00
|
|
|
}
|
|
|
|
|
2019-05-08 08:11:30 +02:00
|
|
|
function set_digest_emails_weekday_visibility() {
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_digest_weekday",
|
|
|
|
page_params.realm_digest_emails_enabled,
|
|
|
|
);
|
2019-05-08 08:11:30 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function populate_realm_domains(realm_domains) {
|
2017-04-08 18:13:39 +02:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
const domains_list = realm_domains.map((realm_domain) =>
|
|
|
|
realm_domain.allow_subdomains ? "*." + realm_domain.domain : realm_domain.domain,
|
js: Convert _.map(a, …) to a.map(…).
And convert the corresponding function expressions to arrow style
while we’re here.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitCallExpression(path) {
const { callee, arguments: args } = path.node;
if (
n.MemberExpression.check(callee) &&
!callee.computed &&
n.Identifier.check(callee.object) &&
callee.object.name === "_" &&
n.Identifier.check(callee.property) &&
callee.property.name === "map" &&
args.length === 2 &&
checkExpression(args[0]) &&
checkExpression(args[1])
) {
const [arr, fn] = args;
path.replace(
b.callExpression(b.memberExpression(arr, b.identifier("map")), [
n.FunctionExpression.check(fn) ||
n.ArrowFunctionExpression.check(fn)
? b.arrowFunctionExpression(
fn.params,
n.BlockStatement.check(fn.body) &&
fn.body.body.length === 1 &&
n.ReturnStatement.check(fn.body.body[0])
? fn.body.body[0].argument || b.identifier("undefined")
: fn.body
)
: fn,
])
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 02:43:49 +01:00
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
let domains = domains_list.join(", ");
|
2017-04-08 18:13:39 +02:00
|
|
|
if (domains.length === 0) {
|
2021-04-13 06:51:54 +02:00
|
|
|
domains = $t({defaultMessage: "None"});
|
2017-04-08 18:13:39 +02:00
|
|
|
}
|
2021-04-13 06:51:54 +02:00
|
|
|
$("#allowed_domains_label").text($t({defaultMessage: "Allowed domains: {domains}"}, {domains}));
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const realm_domains_table_body = $("#realm_domains_table tbody").expectOne();
|
2017-04-08 18:13:39 +02:00
|
|
|
realm_domains_table_body.find("tr").remove();
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
|
|
|
|
for (const realm_domain of realm_domains) {
|
2019-07-09 21:24:00 +02:00
|
|
|
realm_domains_table_body.append(
|
|
|
|
render_settings_admin_realm_domains_list({
|
2020-07-20 22:18:43 +02:00
|
|
|
realm_domain,
|
2020-07-02 02:16:03 +02:00
|
|
|
}),
|
2019-07-09 21:24:00 +02:00
|
|
|
);
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
|
|
|
|
2019-04-07 18:56:32 +02:00
|
|
|
function sort_object_by_key(obj) {
|
2020-02-09 04:45:48 +01:00
|
|
|
const keys = Object.keys(obj).sort();
|
2019-11-02 00:06:25 +01:00
|
|
|
const new_obj = {};
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
|
|
|
|
for (const key of keys) {
|
2019-04-07 18:56:32 +02:00
|
|
|
new_obj[key] = obj[key];
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
|
|
|
|
2019-04-07 18:56:32 +02:00
|
|
|
return new_obj;
|
|
|
|
}
|
2021-02-28 01:20:46 +01:00
|
|
|
|
|
|
|
export function populate_auth_methods(auth_methods) {
|
2017-04-08 18:13:39 +02:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
2019-11-02 00:06:25 +01:00
|
|
|
const auth_methods_table = $("#id_realm_authentication_methods").expectOne();
|
2019-04-07 18:56:32 +02:00
|
|
|
auth_methods = sort_object_by_key(auth_methods);
|
2019-11-02 00:06:25 +01:00
|
|
|
let rendered_auth_method_rows = "";
|
2020-02-06 04:27:31 +01:00
|
|
|
for (const [auth_method, value] of Object.entries(auth_methods)) {
|
2019-07-09 21:24:00 +02:00
|
|
|
rendered_auth_method_rows += render_settings_admin_auth_methods_list({
|
2019-04-06 08:43:34 +02:00
|
|
|
method: auth_method,
|
|
|
|
enabled: value,
|
2020-06-11 16:24:15 +02:00
|
|
|
is_owner: page_params.is_owner,
|
2019-04-06 08:43:34 +02:00
|
|
|
});
|
2020-02-06 04:27:31 +01:00
|
|
|
}
|
2019-04-06 08:43:34 +02:00
|
|
|
auth_methods_table.html(rendered_auth_method_rows);
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2018-04-01 08:56:18 +02:00
|
|
|
function update_dependent_subsettings(property_name) {
|
js: Convert a.indexOf(…) !== -1 to a.includes(…).
Babel polyfills this for us for Internet Explorer.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import K from "ast-types/gen/kinds";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
recast.visit(ast, {
visitBinaryExpression(path) {
const { operator, left, right } = path.node;
if (
n.CallExpression.check(left) &&
n.MemberExpression.check(left.callee) &&
!left.callee.computed &&
n.Identifier.check(left.callee.property) &&
left.callee.property.name === "indexOf" &&
left.arguments.length === 1 &&
checkExpression(left.arguments[0]) &&
((["===", "!==", "==", "!=", ">", "<="].includes(operator) &&
n.UnaryExpression.check(right) &&
right.operator == "-" &&
n.Literal.check(right.argument) &&
right.argument.value === 1) ||
([">=", "<"].includes(operator) &&
n.Literal.check(right) &&
right.value === 0))
) {
const test = b.callExpression(
b.memberExpression(left.callee.object, b.identifier("includes")),
[left.arguments[0]]
);
path.replace(
["!==", "!=", ">", ">="].includes(operator)
? test
: b.unaryExpression("!", test)
);
changed = true;
}
this.traverse(path);
},
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-08 04:55:06 +01:00
|
|
|
if (simple_dropdown_properties.includes(property_name)) {
|
2020-02-03 12:40:36 +01:00
|
|
|
set_property_dropdown_value(property_name);
|
2021-05-09 23:36:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (property_name) {
|
|
|
|
case "realm_waiting_period_threshold":
|
|
|
|
set_realm_waiting_period_dropdown();
|
|
|
|
break;
|
|
|
|
case "realm_video_chat_provider":
|
|
|
|
set_video_chat_provider_dropdown();
|
|
|
|
break;
|
|
|
|
case "realm_msg_edit_limit_setting":
|
|
|
|
case "realm_message_content_edit_limit_minutes":
|
|
|
|
set_msg_edit_limit_dropdown();
|
|
|
|
break;
|
|
|
|
case "realm_message_retention_days":
|
|
|
|
set_message_retention_setting_dropdown();
|
|
|
|
break;
|
|
|
|
case "realm_msg_delete_limit_setting":
|
|
|
|
case "realm_message_content_delete_limit_minutes":
|
|
|
|
set_msg_delete_limit_dropdown();
|
|
|
|
break;
|
2021-06-08 13:45:14 +02:00
|
|
|
case "realm_delete_own_message_policy":
|
|
|
|
set_delete_own_message_policy_dropdown();
|
|
|
|
break;
|
2021-05-09 23:36:58 +02:00
|
|
|
case "realm_org_join_restrictions":
|
|
|
|
set_org_join_restrictions_dropdown();
|
|
|
|
break;
|
|
|
|
case "realm_message_content_allowed_in_email_notifications":
|
|
|
|
set_message_content_in_email_notifications_visiblity();
|
|
|
|
break;
|
|
|
|
case "realm_digest_emails_enabled":
|
2021-08-26 13:04:03 +02:00
|
|
|
settings_notifications.set_enable_digest_emails_visibility(
|
2021-09-30 12:00:57 +02:00
|
|
|
settings_notifications.user_settings_panel,
|
2021-08-26 13:04:03 +02:00
|
|
|
);
|
2021-09-16 12:47:12 +02:00
|
|
|
settings_notifications.set_enable_digest_emails_visibility(
|
2021-09-30 12:00:57 +02:00
|
|
|
settings_realm_user_settings_defaults.realm_default_settings_panel,
|
2021-09-16 12:47:12 +02:00
|
|
|
);
|
2021-05-09 23:36:58 +02:00
|
|
|
set_digest_emails_weekday_visibility();
|
|
|
|
break;
|
2018-03-29 12:52:57 +02:00
|
|
|
}
|
2018-04-01 08:49:10 +02:00
|
|
|
}
|
2018-03-29 12:52:57 +02:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export let default_code_language_widget = null;
|
|
|
|
export let notifications_stream_widget = null;
|
|
|
|
export let signup_notifications_stream_widget = null;
|
2021-02-28 01:38:10 +01:00
|
|
|
|
2018-03-29 12:58:35 +02:00
|
|
|
function discard_property_element_changes(elem) {
|
|
|
|
elem = $(elem);
|
2021-02-28 01:20:46 +01:00
|
|
|
const property_name = extract_property_name(elem);
|
2019-11-02 00:06:25 +01:00
|
|
|
const property_value = get_property_value(property_name);
|
2018-03-29 12:58:35 +02:00
|
|
|
|
2021-05-09 23:36:58 +02:00
|
|
|
switch (property_name) {
|
|
|
|
case "realm_authentication_methods":
|
|
|
|
populate_auth_methods(property_value);
|
|
|
|
break;
|
|
|
|
case "realm_notifications_stream_id":
|
|
|
|
notifications_stream_widget.render(property_value);
|
|
|
|
break;
|
|
|
|
case "realm_signup_notifications_stream_id":
|
|
|
|
signup_notifications_stream_widget.render(property_value);
|
|
|
|
break;
|
|
|
|
case "realm_default_code_block_language":
|
|
|
|
default_code_language_widget.render(property_value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (property_value !== undefined) {
|
|
|
|
set_input_element_value(elem, property_value);
|
|
|
|
} else {
|
|
|
|
blueslip.error("Element refers to unknown property " + property_name);
|
|
|
|
}
|
2018-03-29 12:58:35 +02:00
|
|
|
}
|
|
|
|
|
2018-04-01 08:56:18 +02:00
|
|
|
update_dependent_subsettings(property_name);
|
2018-03-29 12:58:35 +02:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function sync_realm_settings(property) {
|
2018-03-29 13:15:50 +02:00
|
|
|
if (!overlays.settings_open()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-13 10:39:36 +02:00
|
|
|
const value = page_params[`realm_${property}`];
|
2021-05-09 23:36:58 +02:00
|
|
|
switch (property) {
|
|
|
|
case "notifications_stream_id":
|
|
|
|
notifications_stream_widget.render(value);
|
|
|
|
break;
|
|
|
|
case "signup_notifications_stream_id":
|
|
|
|
signup_notifications_stream_widget.render(value);
|
|
|
|
break;
|
|
|
|
case "default_code_block_language":
|
|
|
|
default_code_language_widget.render(value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (property) {
|
|
|
|
case "message_content_edit_limit_seconds":
|
|
|
|
property = "message_content_edit_limit_minutes";
|
|
|
|
break;
|
|
|
|
case "allow_message_editing":
|
|
|
|
property = "msg_edit_limit_setting";
|
|
|
|
break;
|
|
|
|
case "emails_restricted_to_domains":
|
|
|
|
case "disallow_disposable_email_addresses":
|
|
|
|
property = "org_join_restrictions";
|
|
|
|
break;
|
|
|
|
case "message_content_delete_limit_seconds":
|
|
|
|
property = "message_content_delete_limit_minutes";
|
|
|
|
break;
|
2020-07-15 01:29:15 +02:00
|
|
|
}
|
2021-02-03 23:23:32 +01:00
|
|
|
const element = $(`#id_realm_${CSS.escape(property)}`);
|
2018-03-29 13:15:50 +02:00
|
|
|
if (element.length) {
|
|
|
|
discard_property_element_changes(element);
|
|
|
|
}
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2019-03-07 15:18:10 +01:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function change_save_button_state($element, state) {
|
2019-03-07 15:18:10 +01:00
|
|
|
function show_hide_element($element, show, fadeout_delay) {
|
|
|
|
if (show) {
|
2020-07-15 01:29:15 +02:00
|
|
|
$element.removeClass("hide").addClass(".show").fadeIn(300);
|
2019-03-07 15:18:10 +01:00
|
|
|
return;
|
|
|
|
}
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2019-03-07 15:18:10 +01:00
|
|
|
$element.fadeOut(300);
|
|
|
|
}, fadeout_delay);
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const $saveBtn = $element.find(".save-button");
|
2020-09-01 07:54:40 +02:00
|
|
|
const $textEl = $saveBtn.find(".save-discard-widget-button-text");
|
2019-03-07 15:18:10 +01:00
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
if (state !== "saving") {
|
2020-07-15 01:29:15 +02:00
|
|
|
$saveBtn.removeClass("saving");
|
2018-03-29 02:02:01 +02:00
|
|
|
}
|
2019-03-07 15:18:10 +01:00
|
|
|
|
|
|
|
if (state === "discarded") {
|
2019-08-18 14:48:40 +02:00
|
|
|
show_hide_element($element, false, 0);
|
2019-03-07 15:18:10 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let button_text;
|
|
|
|
let data_status;
|
|
|
|
let is_show;
|
2021-05-09 23:36:58 +02:00
|
|
|
switch (state) {
|
|
|
|
case "unsaved":
|
|
|
|
button_text = $t({defaultMessage: "Save changes"});
|
|
|
|
data_status = "unsaved";
|
|
|
|
is_show = true;
|
|
|
|
|
|
|
|
$element.find(".discard-button").show();
|
|
|
|
break;
|
|
|
|
case "saved":
|
|
|
|
button_text = $t({defaultMessage: "Save changes"});
|
|
|
|
data_status = "";
|
|
|
|
is_show = false;
|
|
|
|
break;
|
|
|
|
case "saving":
|
|
|
|
button_text = $t({defaultMessage: "Saving"});
|
|
|
|
data_status = "saving";
|
|
|
|
is_show = true;
|
|
|
|
|
|
|
|
$element.find(".discard-button").hide();
|
|
|
|
$saveBtn.addClass("saving");
|
|
|
|
break;
|
|
|
|
case "failed":
|
|
|
|
button_text = $t({defaultMessage: "Save changes"});
|
|
|
|
data_status = "failed";
|
|
|
|
is_show = true;
|
|
|
|
break;
|
|
|
|
case "succeeded":
|
|
|
|
button_text = $t({defaultMessage: "Saved"});
|
|
|
|
data_status = "saved";
|
|
|
|
is_show = false;
|
|
|
|
break;
|
2019-03-09 08:34:53 +01:00
|
|
|
}
|
|
|
|
|
2019-03-07 15:18:10 +01:00
|
|
|
$textEl.text(button_text);
|
|
|
|
$saveBtn.attr("data-status", data_status);
|
|
|
|
show_hide_element($element, is_show, 800);
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2018-03-29 02:02:01 +02:00
|
|
|
|
2020-05-11 15:11:29 +02:00
|
|
|
function get_input_type(input_elem, input_type) {
|
|
|
|
if (["boolean", "string", "number"].includes(input_type)) {
|
|
|
|
return input_type;
|
|
|
|
}
|
|
|
|
return input_elem.data("setting-widget-type");
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function get_input_element_value(input_elem, input_type) {
|
2020-03-22 16:13:50 +01:00
|
|
|
input_elem = $(input_elem);
|
2020-05-11 15:11:29 +02:00
|
|
|
input_type = get_input_type(input_elem, input_type);
|
2021-05-09 23:36:58 +02:00
|
|
|
switch (input_type) {
|
|
|
|
case "boolean":
|
2020-07-15 01:29:15 +02:00
|
|
|
return input_elem.prop("checked");
|
2021-05-09 23:36:58 +02:00
|
|
|
case "string":
|
2020-03-22 16:13:50 +01:00
|
|
|
return input_elem.val().trim();
|
2021-05-09 23:36:58 +02:00
|
|
|
case "number":
|
2020-10-07 09:17:30 +02:00
|
|
|
return Number.parseInt(input_elem.val().trim(), 10);
|
2021-05-09 23:36:58 +02:00
|
|
|
default:
|
|
|
|
return undefined;
|
2020-03-22 16:13:50 +01:00
|
|
|
}
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2020-03-22 16:13:50 +01:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function set_input_element_value(input_elem, value) {
|
2020-05-11 15:44:01 +02:00
|
|
|
const input_type = get_input_type(input_elem, typeof value);
|
|
|
|
if (input_type) {
|
2020-07-15 01:29:15 +02:00
|
|
|
if (input_type === "boolean") {
|
|
|
|
return input_elem.prop("checked", value);
|
2021-05-09 23:36:58 +02:00
|
|
|
} else if (input_type === "string" || input_type === "number") {
|
2020-05-11 15:44:01 +02:00
|
|
|
return input_elem.val(value);
|
|
|
|
}
|
|
|
|
}
|
2021-02-28 01:20:46 +01:00
|
|
|
blueslip.error(`Failed to set value of property ${extract_property_name(input_elem)}`);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2020-05-11 15:44:01 +02:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function set_up() {
|
|
|
|
build_page();
|
|
|
|
maybe_disable_widgets();
|
|
|
|
}
|
2018-12-08 18:16:37 +01:00
|
|
|
|
2020-04-10 04:43:37 +02:00
|
|
|
function get_auth_method_table_data() {
|
|
|
|
const new_auth_methods = {};
|
2020-07-15 01:29:15 +02:00
|
|
|
const auth_method_rows = $("#id_realm_authentication_methods").find("tr.method_row");
|
2020-04-10 04:43:37 +02:00
|
|
|
|
|
|
|
for (const method_row of auth_method_rows) {
|
2020-07-15 00:34:28 +02:00
|
|
|
new_auth_methods[$(method_row).data("method")] = $(method_row)
|
|
|
|
.find("input")
|
|
|
|
.prop("checked");
|
2020-04-10 04:43:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new_auth_methods;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_property_changed(elem) {
|
|
|
|
elem = $(elem);
|
2021-02-28 01:20:46 +01:00
|
|
|
const property_name = extract_property_name(elem);
|
2020-04-10 04:43:37 +02:00
|
|
|
let current_val = get_property_value(property_name);
|
2020-05-07 11:45:55 +02:00
|
|
|
let changed_val;
|
2020-04-10 04:43:37 +02:00
|
|
|
|
2021-05-09 23:36:58 +02:00
|
|
|
switch (property_name) {
|
|
|
|
case "realm_authentication_methods":
|
|
|
|
current_val = sort_object_by_key(current_val);
|
|
|
|
current_val = JSON.stringify(current_val);
|
|
|
|
changed_val = get_auth_method_table_data();
|
|
|
|
changed_val = JSON.stringify(changed_val);
|
|
|
|
break;
|
|
|
|
case "realm_notifications_stream_id":
|
|
|
|
changed_val = Number.parseInt(notifications_stream_widget.value(), 10);
|
|
|
|
break;
|
|
|
|
case "realm_signup_notifications_stream_id":
|
|
|
|
changed_val = Number.parseInt(signup_notifications_stream_widget.value(), 10);
|
|
|
|
break;
|
|
|
|
case "realm_default_code_block_language":
|
|
|
|
changed_val = default_code_language_widget.value();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (current_val !== undefined) {
|
|
|
|
changed_val = get_input_element_value(elem, typeof current_val);
|
|
|
|
} else {
|
|
|
|
blueslip.error("Element refers to unknown property " + property_name);
|
|
|
|
}
|
2020-04-10 04:43:37 +02:00
|
|
|
}
|
|
|
|
return current_val !== changed_val;
|
|
|
|
}
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function save_discard_widget_status_handler(subsection) {
|
2020-07-15 01:29:15 +02:00
|
|
|
subsection.find(".subsection-failed-status p").hide();
|
|
|
|
subsection.find(".save-button").show();
|
2020-04-10 04:43:37 +02:00
|
|
|
const properties_elements = get_subsection_property_elements(subsection);
|
2021-01-23 02:36:54 +01:00
|
|
|
const show_change_process_button = properties_elements.some((elem) =>
|
|
|
|
check_property_changed(elem),
|
|
|
|
);
|
2020-04-10 04:43:37 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const save_btn_controls = subsection.find(".subsection-header .save-button-controls");
|
2020-04-10 04:43:37 +02:00
|
|
|
const button_state = show_change_process_button ? "unsaved" : "discarded";
|
2021-02-28 01:20:46 +01:00
|
|
|
change_save_button_state(save_btn_controls, button_state);
|
|
|
|
}
|
2020-04-10 06:30:14 +02:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function init_dropdown_widgets() {
|
2021-04-04 15:15:18 +02:00
|
|
|
const streams = stream_settings_data.get_streams_for_settings_page();
|
2020-04-10 09:38:55 +02:00
|
|
|
const notification_stream_options = {
|
2020-12-22 00:37:36 +01:00
|
|
|
data: streams.map((x) => ({
|
|
|
|
name: x.name,
|
|
|
|
value: x.stream_id.toString(),
|
|
|
|
})),
|
2020-04-30 13:09:48 +02:00
|
|
|
on_update: () => {
|
2021-02-28 01:20:46 +01:00
|
|
|
save_discard_widget_status_handler($("#org-notifications"));
|
2020-04-30 13:09:48 +02:00
|
|
|
},
|
2021-04-13 06:51:54 +02:00
|
|
|
default_text: $t({defaultMessage: "Disabled"}),
|
2020-07-02 01:41:40 +02:00
|
|
|
render_text: (x) => `#${x}`,
|
2020-04-10 09:38:55 +02:00
|
|
|
null_value: -1,
|
|
|
|
};
|
2021-07-27 14:05:22 +02:00
|
|
|
notifications_stream_widget = new DropdownListWidget({
|
2020-12-22 00:37:36 +01:00
|
|
|
widget_name: "realm_notifications_stream_id",
|
|
|
|
value: page_params.realm_notifications_stream_id,
|
|
|
|
...notification_stream_options,
|
|
|
|
});
|
2021-07-27 14:05:22 +02:00
|
|
|
signup_notifications_stream_widget = new DropdownListWidget({
|
2020-12-22 00:37:36 +01:00
|
|
|
widget_name: "realm_signup_notifications_stream_id",
|
|
|
|
value: page_params.realm_signup_notifications_stream_id,
|
|
|
|
...notification_stream_options,
|
|
|
|
});
|
2021-07-27 14:05:22 +02:00
|
|
|
default_code_language_widget = new DropdownListWidget({
|
2020-07-15 01:29:15 +02:00
|
|
|
widget_name: "realm_default_code_block_language",
|
2020-07-02 01:41:40 +02:00
|
|
|
data: Object.keys(pygments_data.langs).map((x) => ({
|
|
|
|
name: x,
|
|
|
|
value: x,
|
|
|
|
})),
|
2020-05-19 00:16:34 +02:00
|
|
|
value: page_params.realm_default_code_block_language,
|
2020-04-30 13:09:48 +02:00
|
|
|
on_update: () => {
|
2021-02-28 01:20:46 +01:00
|
|
|
save_discard_widget_status_handler($("#org-other-settings"));
|
2020-04-30 13:09:48 +02:00
|
|
|
},
|
2021-04-13 06:51:54 +02:00
|
|
|
default_text: $t({defaultMessage: "No language set"}),
|
2020-04-10 09:38:55 +02:00
|
|
|
});
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2020-04-10 04:43:37 +02:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
export function build_page() {
|
2017-04-08 18:13:39 +02:00
|
|
|
meta.loaded = true;
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
loading.make_indicator($("#admin_page_auth_methods_loading_indicator"));
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2020-04-15 04:29:15 +02:00
|
|
|
// Initialize all the dropdown list widgets.
|
2021-02-28 01:20:46 +01:00
|
|
|
init_dropdown_widgets();
|
2017-04-08 18:13:39 +02:00
|
|
|
// Populate realm domains
|
2021-02-28 01:20:46 +01:00
|
|
|
populate_realm_domains(page_params.realm_domains);
|
2017-04-08 18:13:39 +02:00
|
|
|
|
|
|
|
// Populate authentication methods table
|
2021-02-28 01:20:46 +01:00
|
|
|
populate_auth_methods(page_params.realm_authentication_methods);
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2021-01-22 22:29:08 +01:00
|
|
|
for (const property_name of simple_dropdown_properties) {
|
|
|
|
set_property_dropdown_value(property_name);
|
|
|
|
}
|
2017-05-25 00:50:07 +02:00
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
set_realm_waiting_period_dropdown();
|
2018-04-23 14:51:30 +02:00
|
|
|
set_video_chat_provider_dropdown();
|
2021-04-27 21:58:19 +02:00
|
|
|
set_giphy_rating_dropdown();
|
2018-04-02 11:18:40 +02:00
|
|
|
set_msg_edit_limit_dropdown();
|
2017-11-26 09:12:10 +01:00
|
|
|
set_msg_delete_limit_dropdown();
|
2021-06-08 13:45:14 +02:00
|
|
|
set_delete_own_message_policy_dropdown();
|
2020-05-07 13:19:54 +02:00
|
|
|
set_message_retention_setting_dropdown();
|
2018-04-05 00:54:31 +02:00
|
|
|
set_org_join_restrictions_dropdown();
|
2019-01-14 14:04:08 +01:00
|
|
|
set_message_content_in_email_notifications_visiblity();
|
2019-05-08 08:11:30 +02:00
|
|
|
set_digest_emails_weekday_visibility();
|
2018-03-05 19:19:19 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$(".admin-realm-form").on("change input", "input, select, textarea", (e) => {
|
2018-03-14 23:50:17 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2019-08-22 01:48:38 +02:00
|
|
|
// This event handler detects whether after these input
|
|
|
|
// changes, any fields have different values from the current
|
|
|
|
// official values stored in the database and page_params. If
|
|
|
|
// they do, we transition to the "unsaved" state showing the
|
|
|
|
// save/discard widget; otherwise, we hide that widget (the
|
|
|
|
// "discarded" state).
|
2019-08-05 21:11:30 +02:00
|
|
|
|
|
|
|
if ($(e.target).hasClass("no-input-change-detection")) {
|
|
|
|
// This is to prevent input changes detection in elements
|
|
|
|
// within a subsection whose changes should not affect the
|
|
|
|
// visibility of the discard button
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const subsection = $(e.target).closest(".org-subsection-parent");
|
2021-02-28 01:20:46 +01:00
|
|
|
save_discard_widget_status_handler(subsection);
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-03-14 23:50:17 +01:00
|
|
|
});
|
|
|
|
|
2021-06-03 18:15:17 +02:00
|
|
|
$(".organization").on("click", ".subsection-header .subsection-changes-discard button", (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
for (const elem of get_subsection_property_elements(e.target)) {
|
|
|
|
discard_property_element_changes(elem);
|
|
|
|
}
|
|
|
|
const save_btn_controls = $(e.target).closest(".save-button-controls");
|
|
|
|
change_save_button_state(save_btn_controls, "discarded");
|
|
|
|
});
|
2018-03-14 23:52:36 +01:00
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
save_organization_settings = function (data, save_button) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const subsection_parent = save_button.closest(".org-subsection-parent");
|
|
|
|
const save_btn_container = subsection_parent.find(".save-button-controls");
|
|
|
|
const failed_alert_elem = subsection_parent.find(".subsection-failed-status p");
|
2021-02-28 01:20:46 +01:00
|
|
|
change_save_button_state(save_btn_container, "saving");
|
2017-04-08 18:13:39 +02:00
|
|
|
channel.patch({
|
2018-03-14 23:45:42 +01:00
|
|
|
url: "/json/realm",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
|
|
|
success() {
|
2018-03-14 23:45:42 +01:00
|
|
|
failed_alert_elem.hide();
|
2021-02-28 01:20:46 +01:00
|
|
|
change_save_button_state(save_btn_container, "succeeded");
|
2017-05-25 00:50:07 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2021-02-28 01:20:46 +01:00
|
|
|
change_save_button_state(save_btn_container, "failed");
|
2018-04-30 15:27:35 +02:00
|
|
|
save_button.hide();
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.error($t_html({defaultMessage: "Save failed"}), xhr, failed_alert_elem);
|
2017-05-25 00:50:07 +02:00
|
|
|
},
|
|
|
|
});
|
2018-01-11 17:47:37 +01:00
|
|
|
};
|
|
|
|
|
2021-02-28 01:20:46 +01:00
|
|
|
parse_time_limit = function parse_time_limit(elem) {
|
2020-10-07 09:17:30 +02:00
|
|
|
return Math.floor(Number.parseFloat(elem.val(), 10).toFixed(1) * 60);
|
2018-08-04 08:18:21 +02:00
|
|
|
};
|
2018-04-28 15:35:14 +02:00
|
|
|
|
2018-03-21 00:50:00 +01:00
|
|
|
function get_complete_data_for_subsection(subsection) {
|
2019-11-02 00:06:25 +01:00
|
|
|
let data = {};
|
2020-02-21 21:45:34 +01:00
|
|
|
|
2021-05-09 23:36:58 +02:00
|
|
|
switch (subsection) {
|
|
|
|
case "msg_editing": {
|
|
|
|
const edit_limit_setting_value = $("#id_realm_msg_edit_limit_setting").val();
|
|
|
|
if (edit_limit_setting_value === "never") {
|
|
|
|
data.allow_message_editing = false;
|
|
|
|
} else if (edit_limit_setting_value === "custom_limit") {
|
|
|
|
data.message_content_edit_limit_seconds = parse_time_limit(
|
|
|
|
$("#id_realm_message_content_edit_limit_minutes"),
|
|
|
|
);
|
|
|
|
// Disable editing if the parsed time limit is 0 seconds
|
|
|
|
data.allow_message_editing = Boolean(data.message_content_edit_limit_seconds);
|
|
|
|
} else {
|
|
|
|
data.allow_message_editing = true;
|
|
|
|
data.message_content_edit_limit_seconds =
|
|
|
|
settings_config.msg_edit_limit_dropdown_values.get(
|
|
|
|
edit_limit_setting_value,
|
|
|
|
).seconds;
|
|
|
|
}
|
|
|
|
const delete_limit_setting_value = $("#id_realm_msg_delete_limit_setting").val();
|
2021-06-15 15:08:23 +02:00
|
|
|
switch (delete_limit_setting_value) {
|
2021-06-14 18:49:28 +02:00
|
|
|
case "any_time": {
|
|
|
|
data.message_content_delete_limit_seconds = JSON.stringify("unlimited");
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-06-15 15:08:23 +02:00
|
|
|
case "custom_limit": {
|
|
|
|
data.message_content_delete_limit_seconds = parse_time_limit(
|
|
|
|
$("#id_realm_message_content_delete_limit_minutes"),
|
|
|
|
);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
data.message_content_delete_limit_seconds =
|
|
|
|
settings_config.msg_delete_limit_dropdown_values.get(
|
|
|
|
delete_limit_setting_value,
|
|
|
|
).seconds;
|
|
|
|
}
|
2021-05-09 23:36:58 +02:00
|
|
|
}
|
2021-06-08 13:45:14 +02:00
|
|
|
data.delete_own_message_policy = $("#id_realm_delete_own_message_policy").val();
|
2021-05-09 23:36:58 +02:00
|
|
|
break;
|
2018-03-14 23:45:42 +01:00
|
|
|
}
|
2021-05-09 23:36:58 +02:00
|
|
|
case "notifications":
|
|
|
|
data.notifications_stream_id = Number.parseInt(
|
|
|
|
notifications_stream_widget.value(),
|
|
|
|
10,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-05-09 23:36:58 +02:00
|
|
|
data.signup_notifications_stream_id = Number.parseInt(
|
|
|
|
signup_notifications_stream_widget.value(),
|
|
|
|
10,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2021-05-09 23:36:58 +02:00
|
|
|
break;
|
|
|
|
case "message_retention": {
|
|
|
|
const message_retention_setting_value = $(
|
|
|
|
"#id_realm_message_retention_setting",
|
|
|
|
).val();
|
|
|
|
if (message_retention_setting_value === "retain_forever") {
|
2021-08-02 18:43:08 +02:00
|
|
|
data.message_retention_days = JSON.stringify("unlimited");
|
2021-05-09 23:36:58 +02:00
|
|
|
} else {
|
|
|
|
data.message_retention_days = JSON.stringify(
|
|
|
|
get_input_element_value($("#id_realm_message_retention_days")),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
2018-03-22 14:07:52 +01:00
|
|
|
}
|
2021-05-09 23:36:58 +02:00
|
|
|
case "other_settings": {
|
|
|
|
const code_block_language_value = default_code_language_widget.value();
|
|
|
|
// No need to JSON-encode, since this value is already a string.
|
|
|
|
data.default_code_block_language = code_block_language_value;
|
|
|
|
break;
|
2018-03-22 14:07:52 +01:00
|
|
|
}
|
2021-05-09 23:36:58 +02:00
|
|
|
case "org_join": {
|
|
|
|
const org_join_restrictions = $("#id_realm_org_join_restrictions").val();
|
|
|
|
switch (org_join_restrictions) {
|
|
|
|
case "only_selected_domain":
|
|
|
|
data.emails_restricted_to_domains = true;
|
|
|
|
data.disallow_disposable_email_addresses = false;
|
|
|
|
break;
|
|
|
|
case "no_disposable_email":
|
|
|
|
data.emails_restricted_to_domains = false;
|
|
|
|
data.disallow_disposable_email_addresses = true;
|
|
|
|
break;
|
|
|
|
case "no_restriction":
|
|
|
|
data.disallow_disposable_email_addresses = false;
|
|
|
|
data.emails_restricted_to_domains = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const waiting_period_threshold = $("#id_realm_waiting_period_setting").val();
|
|
|
|
switch (waiting_period_threshold) {
|
|
|
|
case "none":
|
|
|
|
data.waiting_period_threshold = 0;
|
|
|
|
break;
|
|
|
|
case "three_days":
|
|
|
|
data.waiting_period_threshold = 3;
|
|
|
|
break;
|
|
|
|
case "custom_days":
|
|
|
|
data.waiting_period_threshold = $(
|
|
|
|
"#id_realm_waiting_period_threshold",
|
|
|
|
).val();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2018-04-30 18:26:59 +02:00
|
|
|
}
|
2021-05-09 23:36:58 +02:00
|
|
|
case "auth_settings":
|
|
|
|
data = {};
|
|
|
|
data.authentication_methods = JSON.stringify(get_auth_method_table_data());
|
|
|
|
break;
|
2018-03-14 23:45:42 +01:00
|
|
|
}
|
2019-03-25 11:52:55 +01:00
|
|
|
return data;
|
2018-03-21 00:50:00 +01:00
|
|
|
}
|
|
|
|
|
2019-05-05 15:13:52 +02:00
|
|
|
function populate_data_for_request(subsection) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {};
|
|
|
|
const properties_elements = get_subsection_property_elements(subsection);
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
|
|
|
|
for (let input_elem of properties_elements) {
|
2019-05-05 15:13:52 +02:00
|
|
|
input_elem = $(input_elem);
|
2019-05-05 15:49:37 +02:00
|
|
|
if (check_property_changed(input_elem)) {
|
2021-02-28 01:20:46 +01:00
|
|
|
const input_value = get_input_element_value(input_elem);
|
2020-05-07 13:30:24 +02:00
|
|
|
if (input_value !== undefined) {
|
2020-07-15 01:29:15 +02:00
|
|
|
const property_name = input_elem.attr("id").replace("id_realm_", "");
|
2021-04-07 22:00:40 +02:00
|
|
|
data[property_name] = input_value;
|
2019-05-05 15:13:52 +02:00
|
|
|
}
|
|
|
|
}
|
js: Automatically convert _.each to for…of.
This commit was automatically generated by the following script,
followed by lint --fix and a few small manual lint-related cleanups.
import * as babelParser from "recast/parsers/babel";
import * as recast from "recast";
import * as tsParser from "recast/parsers/typescript";
import { builders as b, namedTypes as n } from "ast-types";
import { Context } from "ast-types/lib/path-visitor";
import K from "ast-types/gen/kinds";
import { NodePath } from "ast-types/lib/node-path";
import assert from "assert";
import fs from "fs";
import path from "path";
import process from "process";
const checkExpression = (node: n.Node): node is K.ExpressionKind =>
n.Expression.check(node);
const checkStatement = (node: n.Node): node is K.StatementKind =>
n.Statement.check(node);
for (const file of process.argv.slice(2)) {
console.log("Parsing", file);
const ast = recast.parse(fs.readFileSync(file, { encoding: "utf8" }), {
parser: path.extname(file) === ".ts" ? tsParser : babelParser,
});
let changed = false;
let inLoop = false;
let replaceReturn = false;
const visitLoop = (...args: string[]) =>
function(this: Context, path: NodePath) {
for (const arg of args) {
this.visit(path.get(arg));
}
const old = { inLoop };
inLoop = true;
this.visit(path.get("body"));
inLoop = old.inLoop;
return false;
};
recast.visit(ast, {
visitDoWhileStatement: visitLoop("test"),
visitExpressionStatement(path) {
const { expression, comments } = path.node;
let valueOnly;
if (
n.CallExpression.check(expression) &&
n.MemberExpression.check(expression.callee) &&
!expression.callee.computed &&
n.Identifier.check(expression.callee.object) &&
expression.callee.object.name === "_" &&
n.Identifier.check(expression.callee.property) &&
["each", "forEach"].includes(expression.callee.property.name) &&
[2, 3].includes(expression.arguments.length) &&
checkExpression(expression.arguments[0]) &&
(n.FunctionExpression.check(expression.arguments[1]) ||
n.ArrowFunctionExpression.check(expression.arguments[1])) &&
[1, 2].includes(expression.arguments[1].params.length) &&
n.Identifier.check(expression.arguments[1].params[0]) &&
((valueOnly = expression.arguments[1].params[1] === undefined) ||
n.Identifier.check(expression.arguments[1].params[1])) &&
(expression.arguments[2] === undefined ||
n.ThisExpression.check(expression.arguments[2]))
) {
const old = { inLoop, replaceReturn };
inLoop = false;
replaceReturn = true;
this.visit(
path
.get("expression")
.get("arguments")
.get(1)
.get("body")
);
inLoop = old.inLoop;
replaceReturn = old.replaceReturn;
const [right, { body, params }] = expression.arguments;
const loop = b.forOfStatement(
b.variableDeclaration("let", [
b.variableDeclarator(
valueOnly ? params[0] : b.arrayPattern([params[1], params[0]])
),
]),
valueOnly
? right
: b.callExpression(
b.memberExpression(right, b.identifier("entries")),
[]
),
checkStatement(body) ? body : b.expressionStatement(body)
);
loop.comments = comments;
path.replace(loop);
changed = true;
}
this.traverse(path);
},
visitForStatement: visitLoop("init", "test", "update"),
visitForInStatement: visitLoop("left", "right"),
visitForOfStatement: visitLoop("left", "right"),
visitFunction(path) {
this.visit(path.get("params"));
const old = { replaceReturn };
replaceReturn = false;
this.visit(path.get("body"));
replaceReturn = old.replaceReturn;
return false;
},
visitReturnStatement(path) {
if (replaceReturn) {
assert(!inLoop); // could use labeled continue if this ever fires
const { argument, comments } = path.node;
if (argument === null) {
const s = b.continueStatement();
s.comments = comments;
path.replace(s);
} else {
const s = b.expressionStatement(argument);
s.comments = comments;
path.replace(s, b.continueStatement());
}
return false;
}
this.traverse(path);
},
visitWhileStatement: visitLoop("test"),
});
if (changed) {
console.log("Writing", file);
fs.writeFileSync(file, recast.print(ast).code, { encoding: "utf8" });
}
}
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-02-06 06:19:47 +01:00
|
|
|
}
|
|
|
|
|
2019-05-05 15:13:52 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2021-06-03 18:15:17 +02:00
|
|
|
$(".organization").on("click", ".subsection-header .subsection-changes-save button", (e) => {
|
2018-03-21 00:50:00 +01:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const save_button = $(e.currentTarget);
|
2020-07-15 01:29:15 +02:00
|
|
|
const subsection_id = save_button.attr("id").replace("org-submit-", "");
|
|
|
|
const subsection = subsection_id.split("-").join("_");
|
|
|
|
const subsection_elem = save_button.closest(".org-subsection-parent");
|
2018-03-21 00:50:00 +01:00
|
|
|
|
2020-02-09 04:15:38 +01:00
|
|
|
const data = {
|
|
|
|
...populate_data_for_request(subsection_elem),
|
|
|
|
...get_complete_data_for_subsection(subsection),
|
|
|
|
};
|
2021-02-28 01:20:46 +01:00
|
|
|
save_organization_settings(data, save_button);
|
2017-05-25 00:50:07 +02:00
|
|
|
});
|
2017-08-18 01:23:55 +02:00
|
|
|
|
2020-07-02 01:45:54 +02:00
|
|
|
$(".org-subsection-parent").on("keydown", "input", (e) => {
|
2018-03-22 14:16:53 +01:00
|
|
|
e.stopPropagation();
|
2021-05-29 22:18:33 +02:00
|
|
|
if (e.key === "Enter") {
|
2018-03-22 14:16:53 +01:00
|
|
|
e.preventDefault();
|
2020-07-15 00:34:28 +02:00
|
|
|
$(e.target)
|
|
|
|
.closest(".org-subsection-parent")
|
2021-06-03 18:15:17 +02:00
|
|
|
.find(".subsection-changes-save button")
|
2020-07-20 21:24:26 +02:00
|
|
|
.trigger("click");
|
2018-03-22 14:16:53 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#id_realm_msg_edit_limit_setting").on("change", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_edit_limit_dropdown_value = e.target.value;
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_message_content_edit_limit_minutes",
|
|
|
|
msg_edit_limit_dropdown_value === "custom_limit",
|
|
|
|
);
|
2018-04-02 11:18:40 +02:00
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#id_realm_msg_delete_limit_setting").on("change", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const msg_delete_limit_dropdown_value = e.target.value;
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_message_content_delete_limit_minutes",
|
|
|
|
msg_delete_limit_dropdown_value === "custom_limit",
|
|
|
|
);
|
2017-11-26 09:12:10 +01:00
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#id_realm_message_retention_setting").on("change", (e) => {
|
2020-05-07 13:19:54 +02:00
|
|
|
const message_retention_setting_dropdown_value = e.target.value;
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_message_retention_days",
|
|
|
|
message_retention_setting_dropdown_value === "retain_for_period",
|
|
|
|
);
|
2020-05-07 13:19:54 +02:00
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#id_realm_waiting_period_setting").on("change", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const waiting_period_threshold = this.value;
|
2020-07-15 00:34:28 +02:00
|
|
|
change_element_block_display_property(
|
|
|
|
"id_realm_waiting_period_threshold",
|
|
|
|
waiting_period_threshold === "custom_days",
|
|
|
|
);
|
2018-01-05 15:34:10 +01:00
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#id_realm_org_join_restrictions").on("change", (e) => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const org_join_restrictions = e.target.value;
|
|
|
|
const node = $("#allowed_domains_label").parent();
|
2020-07-15 01:29:15 +02:00
|
|
|
if (org_join_restrictions === "only_selected_domain") {
|
2018-04-05 00:54:31 +02:00
|
|
|
node.show();
|
2020-02-08 06:23:59 +01:00
|
|
|
if (page_params.realm_domains.length === 0) {
|
2020-07-15 01:29:15 +02:00
|
|
|
overlays.open_modal("#realm_domains_modal");
|
2018-04-05 00:54:31 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
node.hide();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#id_realm_org_join_restrictions").on("click", (e) => {
|
2018-04-05 00:54:31 +02:00
|
|
|
// This prevents the disappearance of modal when there are
|
|
|
|
// no allowed domains otherwise it gets closed due to
|
|
|
|
// the click event handler attached to `#settings_overlay_container`
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
2018-04-28 21:34:57 +02:00
|
|
|
function fade_status_element(elem) {
|
2020-07-02 01:45:54 +02:00
|
|
|
setTimeout(() => {
|
2018-04-28 21:34:57 +02:00
|
|
|
elem.fadeOut(500);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
|
2017-04-08 18:13:39 +02:00
|
|
|
$("#realm_domains_table").on("click", ".delete_realm_domain", function () {
|
2019-11-02 00:06:25 +01:00
|
|
|
const domain = $(this).parents("tr").find(".domain").text();
|
|
|
|
const url = "/json/realm/domains/" + domain;
|
|
|
|
const realm_domains_info = $(".realm_domains_info");
|
2017-04-08 18:13:39 +02:00
|
|
|
|
|
|
|
channel.del({
|
2020-07-20 22:18:43 +02:00
|
|
|
url,
|
|
|
|
success() {
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.success(
|
|
|
|
$t_html({defaultMessage: "Deleted successfully!"}),
|
|
|
|
realm_domains_info,
|
|
|
|
);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-07-20 21:26:58 +02:00
|
|
|
$("#submit-add-realm-domain").on("click", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
const realm_domains_info = $(".realm_domains_info");
|
|
|
|
const widget = $("#add-realm-domain-widget");
|
|
|
|
const domain = widget.find(".new-realm-domain").val();
|
|
|
|
const allow_subdomains = widget.find(".new-realm-domain-allow-subdomains").prop("checked");
|
|
|
|
const data = {
|
2021-05-04 16:31:26 +02:00
|
|
|
domain,
|
2017-04-08 18:13:39 +02:00
|
|
|
allow_subdomains: JSON.stringify(allow_subdomains),
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.post({
|
|
|
|
url: "/json/realm/domains",
|
2020-07-20 22:18:43 +02:00
|
|
|
data,
|
|
|
|
success() {
|
2017-04-08 18:13:39 +02:00
|
|
|
$("#add-realm-domain-widget .new-realm-domain").val("");
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#add-realm-domain-widget .new-realm-domain-allow-subdomains").prop(
|
|
|
|
"checked",
|
|
|
|
false,
|
|
|
|
);
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.success(
|
|
|
|
$t_html({defaultMessage: "Added successfully!"}),
|
|
|
|
realm_domains_info,
|
|
|
|
);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#realm_domains_table").on("change", ".allow-subdomains", function (e) {
|
|
|
|
e.stopPropagation();
|
2019-11-02 00:06:25 +01:00
|
|
|
const realm_domains_info = $(".realm_domains_info");
|
|
|
|
const domain = $(this).parents("tr").find(".domain").text();
|
2020-07-15 01:29:15 +02:00
|
|
|
const allow_subdomains = $(this).prop("checked");
|
|
|
|
const url = "/json/realm/domains/" + domain;
|
2019-11-02 00:06:25 +01:00
|
|
|
const data = {
|
2017-04-08 18:13:39 +02:00
|
|
|
allow_subdomains: JSON.stringify(allow_subdomains),
|
|
|
|
};
|
|
|
|
|
|
|
|
channel.patch({
|
2020-07-20 22:18:43 +02:00
|
|
|
url,
|
|
|
|
data,
|
|
|
|
success() {
|
2017-04-08 18:13:39 +02:00
|
|
|
if (allow_subdomains) {
|
2020-07-15 00:34:28 +02:00
|
|
|
ui_report.success(
|
2021-04-13 05:18:25 +02:00
|
|
|
$t_html(
|
|
|
|
{defaultMessage: "Update successful: Subdomains allowed for {domain}"},
|
|
|
|
{domain},
|
|
|
|
),
|
2020-07-15 00:34:28 +02:00
|
|
|
realm_domains_info,
|
|
|
|
);
|
2017-04-08 18:13:39 +02:00
|
|
|
} else {
|
2020-07-15 00:34:28 +02:00
|
|
|
ui_report.success(
|
2021-04-13 05:18:25 +02:00
|
|
|
$t_html(
|
|
|
|
{
|
|
|
|
defaultMessage:
|
|
|
|
"Update successful: Subdomains no longer allowed for {domain}",
|
|
|
|
},
|
|
|
|
{domain},
|
|
|
|
),
|
2020-07-15 00:34:28 +02:00
|
|
|
realm_domains_info,
|
|
|
|
);
|
2017-04-08 18:13:39 +02:00
|
|
|
}
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2021-04-13 05:18:25 +02:00
|
|
|
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, realm_domains_info);
|
2018-04-28 21:34:57 +02:00
|
|
|
fade_status_element(realm_domains_info);
|
2017-04-08 18:13:39 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-08 00:30:39 +02:00
|
|
|
function realm_icon_logo_upload_complete(spinner, upload_text, delete_button) {
|
2020-07-15 01:29:15 +02:00
|
|
|
spinner.css({visibility: "hidden"});
|
2020-06-08 00:30:39 +02:00
|
|
|
upload_text.show();
|
|
|
|
delete_button.show();
|
2020-05-27 14:16:04 +02:00
|
|
|
}
|
|
|
|
|
2020-06-08 00:30:39 +02:00
|
|
|
function realm_icon_logo_upload_start(spinner, upload_text, delete_button) {
|
|
|
|
spinner.css({visibility: "visible"});
|
|
|
|
upload_text.hide();
|
|
|
|
delete_button.hide();
|
2020-05-27 14:16:04 +02:00
|
|
|
}
|
|
|
|
|
2020-06-11 01:04:12 +02:00
|
|
|
function upload_realm_logo_or_icon(file_input, night, icon) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const form_data = new FormData();
|
2020-06-17 08:02:33 +02:00
|
|
|
let widget;
|
2020-06-11 01:04:12 +02:00
|
|
|
let url;
|
2018-08-16 01:26:55 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
form_data.append("csrfmiddlewaretoken", csrf_token);
|
2020-02-08 01:53:49 +01:00
|
|
|
for (const [i, file] of Array.prototype.entries.call(file_input[0].files)) {
|
2020-07-15 01:29:15 +02:00
|
|
|
form_data.append("file-" + i, file);
|
2020-02-08 01:53:49 +01:00
|
|
|
}
|
2020-06-11 01:04:12 +02:00
|
|
|
if (icon) {
|
2020-07-15 01:29:15 +02:00
|
|
|
url = "/json/realm/icon";
|
|
|
|
widget = "#realm-icon-upload-widget";
|
2019-01-27 08:25:10 +01:00
|
|
|
} else {
|
2020-06-11 01:04:12 +02:00
|
|
|
if (night) {
|
2020-07-15 01:29:15 +02:00
|
|
|
widget = "#realm-night-logo-upload-widget";
|
2020-06-11 01:04:12 +02:00
|
|
|
} else {
|
2020-07-15 01:29:15 +02:00
|
|
|
widget = "#realm-day-logo-upload-widget";
|
2020-06-11 01:04:12 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
url = "/json/realm/logo";
|
|
|
|
form_data.append("night", JSON.stringify(night));
|
2019-01-27 08:25:10 +01:00
|
|
|
}
|
2020-06-17 08:02:33 +02:00
|
|
|
const spinner = $(`${widget} .upload-spinner-background`).expectOne();
|
2020-07-15 21:20:36 +02:00
|
|
|
const upload_text = $(`${widget} .image-upload-text`).expectOne();
|
2020-07-15 20:58:34 +02:00
|
|
|
const delete_button = $(`${widget} .image-delete-button`).expectOne();
|
2020-06-17 08:02:33 +02:00
|
|
|
const error_field = $(`${widget} .image_file_input_error`).expectOne();
|
2020-06-08 00:30:39 +02:00
|
|
|
realm_icon_logo_upload_start(spinner, upload_text, delete_button);
|
2020-06-11 01:04:12 +02:00
|
|
|
error_field.hide();
|
2018-08-16 01:26:55 +02:00
|
|
|
channel.post({
|
2020-07-20 22:18:43 +02:00
|
|
|
url,
|
2018-08-16 01:26:55 +02:00
|
|
|
data: form_data,
|
|
|
|
cache: false,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
2020-07-20 22:18:43 +02:00
|
|
|
success() {
|
2020-06-08 00:30:39 +02:00
|
|
|
realm_icon_logo_upload_complete(spinner, upload_text, delete_button);
|
2018-08-16 01:26:55 +02:00
|
|
|
},
|
2020-07-20 22:18:43 +02:00
|
|
|
error(xhr) {
|
2020-06-08 00:30:39 +02:00
|
|
|
realm_icon_logo_upload_complete(spinner, upload_text, delete_button);
|
2018-08-16 01:26:55 +02:00
|
|
|
ui_report.error("", xhr, error_field);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2019-02-27 15:45:26 +01:00
|
|
|
|
2020-06-11 01:04:12 +02:00
|
|
|
realm_icon.build_realm_icon_widget(upload_realm_logo_or_icon, null, true);
|
2020-05-08 13:30:34 +02:00
|
|
|
if (page_params.zulip_plan_is_not_limited) {
|
2020-06-11 01:04:12 +02:00
|
|
|
realm_logo.build_realm_logo_widget(upload_realm_logo_or_icon, false);
|
|
|
|
realm_logo.build_realm_logo_widget(upload_realm_logo_or_icon, true);
|
2019-06-12 14:22:37 +02:00
|
|
|
}
|
2019-03-11 16:48:59 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#deactivate_realm_button").on("click", (e) => {
|
2021-05-26 19:31:13 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-01-30 14:58:50 +01:00
|
|
|
|
2021-05-26 19:31:13 +02:00
|
|
|
function do_deactivate_realm() {
|
|
|
|
channel.post({
|
|
|
|
url: "/json/realm/deactivate",
|
|
|
|
error(xhr) {
|
|
|
|
ui_report.error(
|
|
|
|
$t_html({defaultMessage: "Failed"}),
|
|
|
|
xhr,
|
|
|
|
$("#admin-realm-deactivation-status").expectOne(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|
2018-01-30 14:58:50 +01:00
|
|
|
}
|
2021-05-26 19:31:13 +02:00
|
|
|
|
|
|
|
const html_body = render_settings_deactivate_realm_modal();
|
|
|
|
const modal_parent = $(".organization-box");
|
|
|
|
|
|
|
|
confirm_dialog.launch({
|
|
|
|
parent: modal_parent,
|
|
|
|
html_heading: $t_html({defaultMessage: "Deactivate organization"}),
|
|
|
|
help_link: "/help/deactivate-your-organization",
|
|
|
|
html_body,
|
|
|
|
on_click: do_deactivate_realm,
|
2021-06-09 16:35:08 +02:00
|
|
|
fade: true,
|
2018-01-30 14:58:50 +01:00
|
|
|
});
|
|
|
|
});
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|