2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2024-10-03 07:13:43 +02:00
|
|
|
import assert from "minimalistic-assert";
|
|
|
|
import {z} from "zod";
|
2021-03-11 05:43:45 +01:00
|
|
|
|
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";
|
|
|
|
|
2023-10-07 00:09:47 +02:00
|
|
|
import * as audible_notifications from "./audible_notifications";
|
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-03-25 23:20:18 +01:00
|
|
|
import {csrf_token} from "./csrf";
|
2022-10-11 14:20:27 +02:00
|
|
|
import * as dialog_widget from "./dialog_widget";
|
2023-07-19 16:14:00 +02:00
|
|
|
import * as dropdown_widget from "./dropdown_widget";
|
2022-05-03 08:06:40 +02:00
|
|
|
import {$t, $t_html, get_language_name} from "./i18n";
|
2022-09-28 08:27:24 +02:00
|
|
|
import * as keydown_util from "./keydown_util";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as loading from "./loading";
|
2024-01-13 21:01:07 +01:00
|
|
|
import * as pygments_data from "./pygments_data";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as realm_icon from "./realm_icon";
|
|
|
|
import * as realm_logo from "./realm_logo";
|
2021-09-28 09:09:52 +02:00
|
|
|
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";
|
2024-10-03 07:13:43 +02:00
|
|
|
import {
|
|
|
|
type MessageMoveTimeLimitSetting,
|
|
|
|
type SettingOptionValueWithKey,
|
|
|
|
realm_setting_property_schema,
|
|
|
|
realm_user_settings_default_properties_schema,
|
|
|
|
simple_dropdown_realm_settings_schema,
|
|
|
|
stream_settings_property_schema,
|
|
|
|
} from "./settings_components";
|
2023-10-09 23:29:16 +02:00
|
|
|
import * as settings_components from "./settings_components";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as settings_config from "./settings_config";
|
2023-01-20 18:29:34 +01:00
|
|
|
import * as settings_data from "./settings_data";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as settings_notifications from "./settings_notifications";
|
2024-07-18 12:35:07 +02:00
|
|
|
import * as settings_preferences from "./settings_preferences";
|
2021-07-20 14:51:48 +02:00
|
|
|
import * as settings_realm_domains from "./settings_realm_domains";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as settings_ui from "./settings_ui";
|
2024-10-03 07:13:43 +02:00
|
|
|
import {current_user, group_setting_value_schema, realm, realm_schema} from "./state_data";
|
|
|
|
import type {Realm} from "./state_data";
|
2021-04-04 15:15:18 +02:00
|
|
|
import * as stream_settings_data from "./stream_settings_data";
|
2024-10-03 07:13:43 +02:00
|
|
|
import type {StreamSubscription} from "./sub_store";
|
|
|
|
import type {HTMLSelectOneElement} from "./types";
|
2021-02-28 01:20:46 +01:00
|
|
|
import * as ui_report from "./ui_report";
|
2023-08-03 16:06:40 +02:00
|
|
|
import * as user_groups from "./user_groups";
|
2024-10-03 07:13:43 +02:00
|
|
|
import type {UserGroup, UserGroupForDropdownListWidget} from "./user_groups";
|
2024-01-05 15:27:32 +01:00
|
|
|
import * as util from "./util";
|
2021-02-28 01:20:46 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const meta = {
|
2017-04-08 18:13:39 +02:00
|
|
|
loaded: false,
|
|
|
|
};
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function reset(): void {
|
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
|
|
|
|
2023-07-19 16:14:00 +02:00
|
|
|
const DISABLED_STATE_ID = -1;
|
2023-01-20 13:25:32 +01:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function maybe_disable_widgets(): void {
|
2024-02-13 02:08:16 +01:00
|
|
|
if (current_user.is_owner) {
|
2020-06-11 13:26:27 +02:00
|
|
|
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
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
if (current_user.is_admin) {
|
2022-10-11 14:20:27 +02:00
|
|
|
$(".deactivate_realm_button").prop("disabled", true);
|
2023-01-25 18:50:46 +01:00
|
|
|
$("#deactivate_realm_button_container").addClass("disabled_setting_tooltip");
|
2020-07-22 02:59:06 +02:00
|
|
|
$("#org-message-retention").find("input, select").prop("disabled", true);
|
2023-08-03 16:06:40 +02:00
|
|
|
$("#org-join-settings").find("input, select, button").prop("disabled", true);
|
2021-07-29 13:53:27 +02:00
|
|
|
$("#id_realm_invite_required_label").parent().addClass("control-label-disabled");
|
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
|
|
|
|
2023-01-05 16:59:18 +01:00
|
|
|
$(".organization-box [data-name='organization-profile']").find(".image_upload_button").hide();
|
|
|
|
|
2024-06-26 10:06:58 +02:00
|
|
|
$(".organization-box [data-name='organization-profile']")
|
|
|
|
.find("input[type='checkbox']:disabled")
|
|
|
|
.closest(".input-group")
|
|
|
|
.addClass("control-label-disabled");
|
|
|
|
|
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
|
|
|
|
2021-11-16 10:40:36 +01:00
|
|
|
$(".organization-box [data-name='organization-settings']")
|
|
|
|
.find(".dropdown_list_reset_button")
|
|
|
|
.hide();
|
|
|
|
|
2018-12-08 17:37:57 +01:00
|
|
|
$(".organization-box [data-name='organization-settings']")
|
2024-06-26 10:06:58 +02:00
|
|
|
.find("input[type='checkbox']:disabled")
|
|
|
|
.closest(".input-group")
|
|
|
|
.addClass("control-label-disabled");
|
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']")
|
2024-06-26 10:06:58 +02:00
|
|
|
.find("input[type='checkbox']:disabled")
|
|
|
|
.closest(".input-group")
|
|
|
|
.addClass("control-label-disabled");
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2018-12-08 17:37:57 +01:00
|
|
|
|
2024-10-27 11:31:15 +01:00
|
|
|
export function enable_or_disable_group_permission_settings(): void {
|
|
|
|
if (current_user.is_owner) {
|
|
|
|
const $permission_pill_container_elements = $("#organization-permissions").find(
|
|
|
|
".pill-container",
|
|
|
|
);
|
|
|
|
$permission_pill_container_elements.find(".input").prop("contenteditable", true);
|
|
|
|
$permission_pill_container_elements
|
|
|
|
.closest(".input-group")
|
|
|
|
.removeClass("group_setting_disabled");
|
|
|
|
settings_components.enable_opening_typeahead_on_clicking_label(
|
|
|
|
$("#organization-permissions"),
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-10-28 12:09:28 +01:00
|
|
|
if (current_user.is_admin) {
|
|
|
|
const $permission_pill_container_elements = $("#organization-permissions").find(
|
|
|
|
".pill-container",
|
|
|
|
);
|
|
|
|
$permission_pill_container_elements.find(".input").prop("contenteditable", true);
|
|
|
|
$permission_pill_container_elements
|
|
|
|
.closest(".input-group")
|
|
|
|
.removeClass("group_setting_disabled");
|
|
|
|
settings_components.enable_opening_typeahead_on_clicking_label(
|
|
|
|
$("#organization-permissions"),
|
|
|
|
);
|
|
|
|
|
2024-10-28 15:06:21 +01:00
|
|
|
// Admins are not allowed to update organization joining and group
|
|
|
|
// related settings.
|
|
|
|
const owner_editable_settings = [
|
|
|
|
"realm_create_multiuse_invite_group",
|
|
|
|
"realm_can_create_groups",
|
|
|
|
"realm_can_manage_all_groups",
|
|
|
|
];
|
2024-10-28 12:09:28 +01:00
|
|
|
for (const setting_name of owner_editable_settings) {
|
|
|
|
const $permission_pill_container = $(`#id_${CSS.escape(setting_name)}`);
|
|
|
|
$permission_pill_container.find(".input").prop("contenteditable", false);
|
|
|
|
$permission_pill_container.closest(".input-group").addClass("group_setting_disabled");
|
|
|
|
settings_components.disable_opening_typeahead_on_clicking_label(
|
|
|
|
$permission_pill_container.closest(".input-group"),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-10-27 11:31:15 +01:00
|
|
|
const $permission_pill_container_elements = $("#organization-permissions").find(
|
|
|
|
".pill-container",
|
|
|
|
);
|
|
|
|
$permission_pill_container_elements.find(".input").prop("contenteditable", false);
|
|
|
|
$permission_pill_container_elements.closest(".input-group").addClass("group_setting_disabled");
|
|
|
|
settings_components.disable_opening_typeahead_on_clicking_label($("#organization-permissions"));
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
type OrganizationSettingsOptions = {
|
|
|
|
common_policy_values: SettingOptionValueWithKey[];
|
|
|
|
wildcard_mention_policy_values: SettingOptionValueWithKey[];
|
|
|
|
invite_to_realm_policy_values: SettingOptionValueWithKey[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export function get_organization_settings_options(): OrganizationSettingsOptions {
|
|
|
|
return {
|
|
|
|
common_policy_values: settings_components.get_sorted_options_list(
|
|
|
|
settings_config.common_policy_values,
|
|
|
|
),
|
|
|
|
wildcard_mention_policy_values: settings_components.get_sorted_options_list(
|
|
|
|
settings_config.wildcard_mention_policy_values,
|
|
|
|
),
|
|
|
|
invite_to_realm_policy_values: settings_components.get_sorted_options_list(
|
|
|
|
settings_config.email_invite_to_realm_policy_values,
|
|
|
|
),
|
|
|
|
};
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2020-01-23 07:01:34 +01:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
type DefinedOrgTypeValues = typeof settings_config.defined_org_type_values;
|
|
|
|
type AllOrgTypeValues = typeof settings_config.all_org_type_values;
|
|
|
|
|
|
|
|
export function get_org_type_dropdown_options(): DefinedOrgTypeValues | AllOrgTypeValues {
|
2024-02-13 02:08:24 +01:00
|
|
|
const current_org_type = realm.realm_org_type;
|
2022-04-12 17:41:07 +02:00
|
|
|
if (current_org_type !== 0) {
|
|
|
|
return settings_config.defined_org_type_values;
|
|
|
|
}
|
|
|
|
return settings_config.all_org_type_values;
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
const simple_dropdown_properties = simple_dropdown_realm_settings_schema.keyof().options;
|
2020-02-03 12:40:36 +01:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_realm_waiting_period_setting(): void {
|
2024-02-13 02:08:24 +01:00
|
|
|
const setting_value = realm.realm_waiting_period_threshold;
|
2022-12-12 18:21:08 +01:00
|
|
|
const valid_limit_values = settings_config.waiting_period_threshold_dropdown_values.map(
|
|
|
|
(x) => x.code,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (valid_limit_values.includes(setting_value)) {
|
|
|
|
$("#id_realm_waiting_period_threshold").val(setting_value);
|
|
|
|
} else {
|
|
|
|
$("#id_realm_waiting_period_threshold").val("custom_period");
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#id_realm_waiting_period_threshold_custom_input").val(setting_value);
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2022-12-13 12:32:01 +01:00
|
|
|
"id_realm_waiting_period_threshold_custom_input",
|
2022-12-12 18:21:08 +01:00
|
|
|
$("#id_realm_waiting_period_threshold").val() === "custom_period",
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2018-04-01 08:49:10 +02:00
|
|
|
}
|
2018-01-05 15:34:10 +01:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function update_jitsi_server_url_custom_input(dropdown_val: string): void {
|
2023-09-19 18:10:23 +02:00
|
|
|
const custom_input = "id_realm_jitsi_server_url_custom_input";
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
|
|
|
custom_input,
|
|
|
|
dropdown_val === "custom",
|
|
|
|
);
|
2023-09-19 18:10:23 +02:00
|
|
|
|
|
|
|
if (dropdown_val !== "custom") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const $custom_input_elem = $(`#${CSS.escape(custom_input)}`);
|
2024-10-07 06:04:32 +02:00
|
|
|
$custom_input_elem.val(realm.realm_jitsi_server_url ?? "");
|
2023-09-19 18:10:23 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_jitsi_server_url_dropdown(): void {
|
2023-10-09 23:29:16 +02:00
|
|
|
if (!settings_components.is_video_chat_provider_jitsi_meet()) {
|
2023-09-19 18:10:23 +02:00
|
|
|
$("#realm_jitsi_server_url_setting").hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#realm_jitsi_server_url_setting").show();
|
|
|
|
|
|
|
|
let dropdown_val = "server_default";
|
2024-02-13 02:08:24 +01:00
|
|
|
if (realm.realm_jitsi_server_url) {
|
2023-09-19 18:10:23 +02:00
|
|
|
dropdown_val = "custom";
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#id_realm_jitsi_server_url").val(dropdown_val);
|
|
|
|
update_jitsi_server_url_custom_input(dropdown_val);
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_video_chat_provider_dropdown(): void {
|
2024-02-13 02:08:24 +01:00
|
|
|
const chat_provider_id = realm.realm_video_chat_provider;
|
2019-05-09 09:54:38 +02:00
|
|
|
$("#id_realm_video_chat_provider").val(chat_provider_id);
|
2023-09-19 18:10:23 +02:00
|
|
|
|
|
|
|
set_jitsi_server_url_dropdown();
|
2018-04-23 14:51:30 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_giphy_rating_dropdown(): void {
|
2024-02-13 02:08:24 +01:00
|
|
|
const rating_id = realm.realm_giphy_rating;
|
2021-04-27 21:58:19 +02:00
|
|
|
$("#id_realm_giphy_rating").val(rating_id);
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function update_message_edit_sub_settings(is_checked: boolean): void {
|
2022-08-19 16:14:15 +02:00
|
|
|
settings_ui.disable_sub_setting_onchange(
|
|
|
|
is_checked,
|
|
|
|
"id_realm_message_content_edit_limit_seconds",
|
|
|
|
true,
|
|
|
|
);
|
2022-04-12 09:56:58 +02:00
|
|
|
settings_ui.disable_sub_setting_onchange(
|
|
|
|
is_checked,
|
|
|
|
"id_realm_message_content_edit_limit_minutes",
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_msg_edit_limit_dropdown(): void {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.set_time_limit_setting("realm_message_content_edit_limit_seconds");
|
2022-09-08 12:19:16 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_msg_move_limit_setting(property_name: MessageMoveTimeLimitSetting): void {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.set_time_limit_setting(property_name);
|
2021-06-08 13:45:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_msg_delete_limit_dropdown(): void {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.set_time_limit_setting("realm_message_content_delete_limit_seconds");
|
2022-11-04 11:11:33 +01:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function get_dropdown_value_for_message_retention_setting(setting_value: number | null): string {
|
2022-11-04 11:11:33 +01:00
|
|
|
if (setting_value === settings_config.retain_message_forever) {
|
2022-11-04 11:11:33 +01:00
|
|
|
return "unlimited";
|
2022-11-04 11:11:33 +01:00
|
|
|
}
|
|
|
|
|
2022-10-18 11:03:09 +02:00
|
|
|
if (setting_value === null) {
|
|
|
|
return "realm_default";
|
|
|
|
}
|
|
|
|
|
2022-11-04 11:11:33 +01:00
|
|
|
return "custom_period";
|
2022-11-04 11:11:33 +01:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function set_message_retention_setting_dropdown(sub: StreamSubscription | undefined): void {
|
|
|
|
let property_name: "message_retention_days" | "realm_message_retention_days";
|
|
|
|
let setting_value: number | null;
|
2022-10-18 11:03:09 +02:00
|
|
|
if (sub !== undefined) {
|
|
|
|
property_name = "message_retention_days";
|
2024-10-03 07:13:43 +02:00
|
|
|
setting_value = sub.message_retention_days;
|
2024-05-20 21:36:38 +02:00
|
|
|
} else {
|
2024-10-03 07:13:43 +02:00
|
|
|
property_name = "realm_message_retention_days";
|
|
|
|
setting_value = realm.realm_message_retention_days;
|
2022-10-18 11:03:09 +02:00
|
|
|
}
|
2022-11-04 11:11:33 +01:00
|
|
|
const dropdown_val = get_dropdown_value_for_message_retention_setting(setting_value);
|
2022-11-04 11:11:33 +01:00
|
|
|
|
2022-11-04 11:11:33 +01:00
|
|
|
const $dropdown_elem = $(`#id_${CSS.escape(property_name)}`);
|
|
|
|
$dropdown_elem.val(dropdown_val);
|
2022-11-04 11:11:33 +01:00
|
|
|
|
2022-11-04 11:11:33 +01:00
|
|
|
const $custom_input_elem = $dropdown_elem
|
|
|
|
.parent()
|
|
|
|
.find(".message-retention-setting-custom-input")
|
|
|
|
.val("");
|
|
|
|
if (dropdown_val === "custom_period") {
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(setting_value !== null);
|
2022-11-04 11:11:33 +01:00
|
|
|
$custom_input_elem.val(setting_value);
|
2020-06-21 11:35:02 +02:00
|
|
|
}
|
2022-11-04 11:11:33 +01:00
|
|
|
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2024-10-03 07:13:43 +02:00
|
|
|
$custom_input_elem.attr("id")!,
|
2022-11-04 11:11:33 +01:00
|
|
|
dropdown_val === "custom_period",
|
|
|
|
);
|
2020-05-07 13:19:54 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_org_join_restrictions_dropdown(): void {
|
2024-05-20 21:36:38 +02:00
|
|
|
const value = settings_components.get_realm_settings_property_value(
|
|
|
|
"realm_org_join_restrictions",
|
|
|
|
);
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(typeof value === "string");
|
2018-04-05 00:54:31 +02:00
|
|
|
$("#id_realm_org_join_restrictions").val(value);
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2020-07-15 00:34:28 +02:00
|
|
|
"allowed_domains_label",
|
|
|
|
value === "only_selected_domain",
|
|
|
|
);
|
2018-04-05 00:54:31 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_message_content_in_email_notifications_visibility(): void {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2020-07-15 01:29:15 +02:00
|
|
|
"message_content_in_email_notifications_label",
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_message_content_allowed_in_email_notifications,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-01-14 14:04:08 +01:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_digest_emails_weekday_visibility(): void {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2020-07-15 00:34:28 +02:00
|
|
|
"id_realm_digest_weekday",
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_digest_emails_enabled,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2019-05-08 08:11:30 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function set_create_web_public_stream_dropdown_visibility(): void {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2024-07-26 05:42:14 +02:00
|
|
|
"id_realm_can_create_web_public_channel_group",
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.server_web_public_streams_enabled &&
|
|
|
|
realm.zulip_plan_is_not_limited &&
|
|
|
|
realm.realm_enable_spectator_access,
|
2021-11-19 10:29:39 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-10-29 14:29:02 +01:00
|
|
|
export function check_disable_direct_message_initiator_group_widget(): void {
|
|
|
|
const direct_message_permission_group_widget = settings_components.get_group_setting_widget(
|
|
|
|
"realm_direct_message_permission_group",
|
|
|
|
);
|
|
|
|
if (direct_message_permission_group_widget === null) {
|
|
|
|
// direct_message_permission_group_widget can be null if
|
|
|
|
// the settings overlay is not opened yet.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(direct_message_permission_group_widget !== null);
|
|
|
|
const direct_message_permission_value = settings_components.get_group_setting_widget_value(
|
|
|
|
direct_message_permission_group_widget,
|
|
|
|
);
|
|
|
|
if (user_groups.is_setting_group_empty(direct_message_permission_value)) {
|
|
|
|
$("#id_realm_direct_message_initiator_group").find(".input").prop("contenteditable", false);
|
|
|
|
$("#id_realm_direct_message_initiator_group")
|
|
|
|
.closest(".input-group")
|
|
|
|
.addClass("group_setting_disabled");
|
|
|
|
settings_components.disable_opening_typeahead_on_clicking_label(
|
|
|
|
$("#id_realm_direct_message_initiator_group").closest(".input-group"),
|
|
|
|
);
|
|
|
|
} else if (current_user.is_admin) {
|
|
|
|
$("#id_realm_direct_message_initiator_group").find(".input").prop("contenteditable", true);
|
|
|
|
$("#id_realm_direct_message_initiator_group")
|
|
|
|
.closest(".input-group")
|
|
|
|
.removeClass("group_setting_disabled");
|
|
|
|
settings_components.enable_opening_typeahead_on_clicking_label(
|
|
|
|
$("#id_realm_direct_message_initiator_group").closest(".input-group"),
|
|
|
|
);
|
2024-07-08 19:00:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function populate_realm_domains_label(
|
|
|
|
realm_domains: {domain: string; allow_subdomains: boolean}[],
|
|
|
|
): void {
|
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
|
|
|
);
|
2024-01-05 15:27:32 +01:00
|
|
|
let domains = util.format_array_as_list(domains_list, "long", "conjunction");
|
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}));
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function can_configure_auth_methods(): boolean {
|
2023-01-20 18:29:34 +01:00
|
|
|
if (settings_data.user_email_not_configured()) {
|
|
|
|
return false;
|
|
|
|
}
|
2024-02-13 02:08:16 +01:00
|
|
|
if (current_user.is_owner) {
|
2023-01-20 18:29:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function populate_auth_methods(auth_method_to_bool_map: Record<string, boolean>): void {
|
2017-04-08 18:13:39 +02:00
|
|
|
if (!meta.loaded) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-07 10:14:13 +02:00
|
|
|
const $auth_methods_list = $("#id_realm_authentication_methods").expectOne();
|
2019-11-02 00:06:25 +01:00
|
|
|
let rendered_auth_method_rows = "";
|
2024-02-05 23:52:25 +01:00
|
|
|
for (const [auth_method, value] of Object.entries(auth_method_to_bool_map)) {
|
|
|
|
// Certain authentication methods are not available to be enabled without
|
|
|
|
// purchasing a plan, so we need to disable them in this UI.
|
|
|
|
// The restriction only applies to **enabling** the auth method, so this
|
|
|
|
// logic is dependent on the current value.
|
|
|
|
// The reason for that is that if for any reason, the auth method is already
|
|
|
|
// enabled (for example, because it was manually enabled for the organization
|
|
|
|
// by request, as an exception) - the organization should be able to disable it
|
|
|
|
// if they don't want it anymore.
|
|
|
|
const cant_be_enabled =
|
2024-10-03 07:13:43 +02:00
|
|
|
!realm.realm_authentication_methods[auth_method]!.available && !value;
|
2024-02-05 23:52:25 +01:00
|
|
|
|
|
|
|
const render_args = {
|
2019-04-06 08:43:34 +02:00
|
|
|
method: auth_method,
|
|
|
|
enabled: value,
|
2024-02-05 23:52:25 +01:00
|
|
|
disable_configure_auth_method: !can_configure_auth_methods() || cant_be_enabled,
|
2022-07-07 10:12:16 +02:00
|
|
|
// The negated character class regexp serves as an allowlist - the replace() will
|
|
|
|
// remove *all* symbols *but* digits (\d) and lowecase letters (a-z),
|
|
|
|
// so that we can make assumptions on this string elsewhere in the code.
|
|
|
|
// As a result, the only two "incoming" assumptions on the auth method name are:
|
|
|
|
// 1) It contains at least one allowed symbol
|
|
|
|
// 2) No two auth method names are identical after this allowlist filtering
|
2023-05-11 21:49:10 +02:00
|
|
|
prefix: "id_authmethod" + auth_method.toLowerCase().replaceAll(/[^\da-z]/g, "") + "_",
|
2024-10-03 07:13:43 +02:00
|
|
|
...(cant_be_enabled && {
|
|
|
|
unavailable_reason:
|
|
|
|
realm.realm_authentication_methods[auth_method]!.unavailable_reason,
|
|
|
|
}),
|
2024-02-05 23:52:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
rendered_auth_method_rows += render_settings_admin_auth_methods_list(render_args);
|
2020-02-06 04:27:31 +01:00
|
|
|
}
|
2022-07-07 10:14:13 +02:00
|
|
|
$auth_methods_list.html(rendered_auth_method_rows);
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2017-04-08 18:13:39 +02:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function update_dependent_subsettings(property_name: string): void {
|
|
|
|
const parsed_property_name = simple_dropdown_realm_settings_schema
|
|
|
|
.keyof()
|
|
|
|
.safeParse(property_name);
|
|
|
|
if (parsed_property_name.success) {
|
|
|
|
settings_components.set_property_dropdown_value(parsed_property_name.data);
|
2021-05-09 23:36:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (property_name) {
|
2022-04-12 09:56:58 +02:00
|
|
|
case "realm_allow_message_editing":
|
2024-02-13 02:08:24 +01:00
|
|
|
update_message_edit_sub_settings(realm.realm_allow_message_editing);
|
2022-04-12 09:56:58 +02:00
|
|
|
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":
|
2023-01-02 20:50:23 +01:00
|
|
|
set_message_content_in_email_notifications_visibility();
|
2021-05-09 23:36:58 +02:00
|
|
|
break;
|
|
|
|
case "realm_digest_emails_enabled":
|
2021-08-26 13:04:03 +02:00
|
|
|
settings_notifications.set_enable_digest_emails_visibility(
|
2023-10-10 02:07:30 +02:00
|
|
|
$("#user-notification-settings"),
|
|
|
|
false,
|
2021-08-26 13:04:03 +02:00
|
|
|
);
|
2021-09-16 12:47:12 +02:00
|
|
|
settings_notifications.set_enable_digest_emails_visibility(
|
2023-10-10 02:07:30 +02:00
|
|
|
$("#realm-user-default-settings"),
|
|
|
|
true,
|
2021-09-16 12:47:12 +02:00
|
|
|
);
|
2021-05-09 23:36:58 +02:00
|
|
|
set_digest_emails_weekday_visibility();
|
|
|
|
break;
|
2021-11-19 10:29:39 +01:00
|
|
|
case "realm_enable_spectator_access":
|
|
|
|
set_create_web_public_stream_dropdown_visibility();
|
|
|
|
break;
|
2024-07-08 19:00:08 +02:00
|
|
|
case "realm_direct_message_permission_group":
|
2024-10-29 14:29:02 +01:00
|
|
|
check_disable_direct_message_initiator_group_widget();
|
2024-07-08 19:00:08 +02:00
|
|
|
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
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function discard_realm_property_element_changes(elem: HTMLElement): void {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elem = $(elem);
|
2024-05-20 21:36:38 +02:00
|
|
|
const property_name = settings_components.extract_property_name($elem);
|
2024-10-03 07:13:43 +02:00
|
|
|
const property_value = settings_components.get_realm_settings_property_value(
|
|
|
|
realm_setting_property_schema.parse(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":
|
2024-03-27 11:03:24 +01:00
|
|
|
populate_auth_methods(
|
|
|
|
settings_components.realm_authentication_methods_to_boolean_dict(),
|
|
|
|
);
|
2021-05-09 23:36:58 +02:00
|
|
|
break;
|
2024-02-07 12:13:02 +01:00
|
|
|
case "realm_new_stream_announcements_stream_id":
|
2024-02-07 17:11:43 +01:00
|
|
|
case "realm_signup_announcements_stream_id":
|
2024-01-26 14:45:37 +01:00
|
|
|
case "realm_zulip_update_announcements_stream_id":
|
2021-05-09 23:36:58 +02:00
|
|
|
case "realm_default_code_block_language":
|
2023-11-23 10:14:35 +01:00
|
|
|
case "realm_can_access_all_users_group":
|
2024-07-26 05:42:14 +02:00
|
|
|
case "realm_can_create_web_public_channel_group":
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(typeof property_value === "string" || typeof property_value === "number");
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.set_dropdown_list_widget_setting_value(
|
|
|
|
property_name,
|
|
|
|
property_value,
|
|
|
|
);
|
2021-05-09 23:36:58 +02:00
|
|
|
break;
|
2024-10-29 11:29:01 +01:00
|
|
|
case "realm_can_add_custom_emoji_group":
|
2024-10-28 15:06:21 +01:00
|
|
|
case "realm_can_create_groups":
|
2024-10-28 12:09:28 +01:00
|
|
|
case "realm_can_create_public_channel_group":
|
|
|
|
case "realm_can_create_private_channel_group":
|
2024-10-30 08:15:27 +01:00
|
|
|
case "realm_can_delete_any_message_group":
|
|
|
|
case "realm_can_delete_own_message_group":
|
2024-10-28 15:06:21 +01:00
|
|
|
case "realm_can_manage_all_groups":
|
2024-10-30 07:50:59 +01:00
|
|
|
case "realm_can_move_messages_between_channels_group":
|
|
|
|
case "realm_can_move_messages_between_topics_group":
|
2024-10-29 14:29:02 +01:00
|
|
|
case "realm_create_multiuse_invite_group":
|
|
|
|
case "realm_direct_message_initiator_group":
|
|
|
|
case "realm_direct_message_permission_group": {
|
2024-10-27 11:31:15 +01:00
|
|
|
const pill_widget = settings_components.get_group_setting_widget(property_name);
|
|
|
|
assert(pill_widget !== null);
|
|
|
|
settings_components.set_group_setting_widget_value(
|
|
|
|
pill_widget,
|
|
|
|
group_setting_value_schema.parse(property_value),
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2022-05-03 08:06:40 +02:00
|
|
|
case "realm_default_language":
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(typeof property_value === "string");
|
2022-05-03 08:06:40 +02:00
|
|
|
$("#org-notifications .language_selection_widget .language_selection_button span").attr(
|
|
|
|
"data-language-code",
|
|
|
|
property_value,
|
|
|
|
);
|
|
|
|
$("#org-notifications .language_selection_widget .language_selection_button span").text(
|
2024-10-03 07:13:43 +02:00
|
|
|
// We know this is defined, since we got the `property_value` from a dropdown
|
|
|
|
// of valid language options.
|
|
|
|
get_language_name(property_value)!,
|
2022-05-03 08:06:40 +02:00
|
|
|
);
|
|
|
|
break;
|
2022-04-12 17:41:07 +02:00
|
|
|
case "realm_org_type":
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(typeof property_value === "number");
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.set_input_element_value($elem, property_value);
|
2022-04-12 17:41:07 +02:00
|
|
|
// Remove 'unspecified' option (value=0) from realm_org_type
|
2024-02-13 02:08:24 +01:00
|
|
|
// dropdown menu options whenever realm.realm_org_type
|
2022-04-12 17:41:07 +02:00
|
|
|
// returns another value.
|
|
|
|
if (property_value !== 0) {
|
|
|
|
$("#id_realm_org_type option[value=0]").remove();
|
|
|
|
}
|
|
|
|
break;
|
2022-09-02 13:07:11 +02:00
|
|
|
case "realm_message_content_edit_limit_seconds":
|
|
|
|
case "realm_message_content_delete_limit_seconds":
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.set_time_limit_setting(property_name);
|
2022-06-03 19:20:32 +02:00
|
|
|
break;
|
2022-12-22 19:14:23 +01:00
|
|
|
case "realm_move_messages_within_stream_limit_seconds":
|
2023-01-30 12:15:36 +01:00
|
|
|
case "realm_move_messages_between_streams_limit_seconds":
|
2022-12-22 19:14:23 +01:00
|
|
|
set_msg_move_limit_setting(property_name);
|
|
|
|
break;
|
2023-09-03 05:17:14 +02:00
|
|
|
case "realm_video_chat_provider":
|
|
|
|
set_video_chat_provider_dropdown();
|
|
|
|
break;
|
2023-09-19 18:10:23 +02:00
|
|
|
case "realm_jitsi_server_url":
|
|
|
|
set_jitsi_server_url_dropdown();
|
|
|
|
break;
|
2022-11-04 11:11:33 +01:00
|
|
|
case "realm_message_retention_days":
|
2024-05-21 15:06:33 +02:00
|
|
|
set_message_retention_setting_dropdown(undefined);
|
|
|
|
break;
|
2022-12-12 18:21:08 +01:00
|
|
|
case "realm_waiting_period_threshold":
|
|
|
|
set_realm_waiting_period_setting();
|
|
|
|
break;
|
2021-05-09 23:36:58 +02:00
|
|
|
default:
|
|
|
|
if (property_value !== undefined) {
|
2024-10-03 07:13:43 +02:00
|
|
|
const validated_property_value = z
|
|
|
|
.union([z.string(), z.number(), z.boolean()])
|
|
|
|
.parse(property_value);
|
|
|
|
settings_components.set_input_element_value($elem, validated_property_value);
|
2021-05-09 23:36:58 +02:00
|
|
|
} else {
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.error("Element refers to unknown property", {property_name});
|
2021-05-09 23:36:58 +02:00
|
|
|
}
|
2018-03-29 12:58:35 +02:00
|
|
|
}
|
2024-05-20 21:36:38 +02:00
|
|
|
update_dependent_subsettings(property_name);
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function discard_stream_property_element_changes(
|
|
|
|
elem: HTMLElement,
|
|
|
|
sub: StreamSubscription,
|
|
|
|
): void {
|
2024-05-20 21:36:38 +02:00
|
|
|
const $elem = $(elem);
|
|
|
|
const property_name = settings_components.extract_property_name($elem);
|
|
|
|
const property_value = settings_components.get_stream_settings_property_value(
|
2024-10-03 07:13:43 +02:00
|
|
|
stream_settings_property_schema.parse(property_name),
|
2024-05-20 21:36:38 +02:00
|
|
|
sub,
|
|
|
|
);
|
|
|
|
switch (property_name) {
|
|
|
|
case "can_remove_subscribers_group":
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(typeof property_value === "number");
|
2024-05-20 21:36:38 +02:00
|
|
|
settings_components.set_dropdown_list_widget_setting_value(
|
|
|
|
property_name,
|
|
|
|
property_value,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "stream_privacy": {
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(typeof property_value === "string");
|
2024-05-20 21:36:38 +02:00
|
|
|
$elem.find(`input[value='${CSS.escape(property_value)}']`).prop("checked", true);
|
2018-03-29 12:58:35 +02:00
|
|
|
|
2024-05-20 21:36:38 +02:00
|
|
|
// Hide stream privacy warning banner
|
|
|
|
const $stream_permissions_warning_banner = $(
|
|
|
|
"#stream_permission_settings .stream-permissions-warning-banner",
|
|
|
|
);
|
|
|
|
if (!$stream_permissions_warning_banner.is(":empty")) {
|
|
|
|
$stream_permissions_warning_banner.empty();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "message_retention_days":
|
|
|
|
set_message_retention_setting_dropdown(sub);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (property_value !== undefined) {
|
2024-10-03 07:13:43 +02:00
|
|
|
const validated_property_value = z
|
|
|
|
.union([z.string(), z.number(), z.boolean()])
|
|
|
|
.parse(property_value);
|
|
|
|
settings_components.set_input_element_value($elem, validated_property_value);
|
2024-05-20 21:36:38 +02:00
|
|
|
} else {
|
|
|
|
blueslip.error("Element refers to unknown property", {property_name});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update_dependent_subsettings(property_name);
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function discard_group_property_element_changes(elem: HTMLElement, group: UserGroup): void {
|
2024-05-20 21:36:38 +02:00
|
|
|
const $elem = $(elem);
|
|
|
|
const property_name = settings_components.extract_property_name($elem);
|
2024-10-03 07:13:43 +02:00
|
|
|
const property_value = settings_components.get_group_property_value(
|
|
|
|
user_groups.user_group_schema.keyof().parse(property_name),
|
|
|
|
group,
|
|
|
|
);
|
2024-05-20 21:36:38 +02:00
|
|
|
|
2024-10-02 13:47:50 +02:00
|
|
|
const group_widget_settings = [...settings_components.group_setting_widget_map.keys()];
|
2024-10-16 06:59:07 +02:00
|
|
|
if (group_widget_settings.includes(property_name)) {
|
2024-10-02 19:47:04 +02:00
|
|
|
const pill_widget = settings_components.get_group_setting_widget(property_name);
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(pill_widget !== null);
|
|
|
|
settings_components.set_group_setting_widget_value(
|
|
|
|
pill_widget,
|
|
|
|
group_setting_value_schema.parse(property_value),
|
|
|
|
);
|
2024-05-20 21:36:38 +02:00
|
|
|
} else {
|
|
|
|
blueslip.error("Element refers to unknown property", {property_name});
|
|
|
|
}
|
|
|
|
update_dependent_subsettings(property_name);
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function discard_realm_default_property_element_changes(elem: HTMLElement): void {
|
2024-05-20 21:36:38 +02:00
|
|
|
const $elem = $(elem);
|
2024-10-03 07:13:43 +02:00
|
|
|
const property_name = realm_user_settings_default_properties_schema.parse(
|
|
|
|
settings_components.extract_property_name($elem, true),
|
|
|
|
);
|
2024-05-20 21:36:38 +02:00
|
|
|
const property_value =
|
|
|
|
settings_components.get_realm_default_setting_property_value(property_name);
|
|
|
|
switch (property_name) {
|
|
|
|
case "notification_sound":
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(typeof property_value === "string");
|
2024-05-20 21:36:38 +02:00
|
|
|
audible_notifications.update_notification_sound_source(
|
|
|
|
$("audio#realm-default-notification-sound-audio"),
|
|
|
|
{
|
|
|
|
notification_sound: property_value,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
settings_components.set_input_element_value($elem, property_value);
|
|
|
|
break;
|
|
|
|
case "emojiset":
|
|
|
|
case "user_list_style":
|
|
|
|
// Because this widget has a radio button structure, it
|
|
|
|
// needs custom reset code.
|
2024-10-03 07:13:43 +02:00
|
|
|
$elem
|
|
|
|
.find(`input[value='${CSS.escape(property_value.toString())}']`)
|
|
|
|
.prop("checked", true);
|
2024-05-20 21:36:38 +02:00
|
|
|
break;
|
|
|
|
case "email_notifications_batching_period_seconds":
|
|
|
|
case "email_notification_batching_period_edit_minutes":
|
|
|
|
settings_notifications.set_notification_batching_ui(
|
|
|
|
$("#realm-user-default-settings"),
|
|
|
|
realm_user_settings_defaults.email_notifications_batching_period_seconds,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (property_value !== undefined) {
|
2024-10-03 07:13:43 +02:00
|
|
|
const validated_property_value = z
|
|
|
|
.union([z.string(), z.number(), z.boolean()])
|
|
|
|
.parse(property_value);
|
|
|
|
settings_components.set_input_element_value($elem, validated_property_value);
|
2024-05-20 21:36:38 +02:00
|
|
|
} else {
|
|
|
|
blueslip.error("Element refers to unknown property", {property_name});
|
|
|
|
}
|
|
|
|
}
|
2018-04-01 08:56:18 +02:00
|
|
|
update_dependent_subsettings(property_name);
|
2018-03-29 12:58:35 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function discard_realm_settings_subsection_changes($subsection: JQuery): void {
|
2024-06-28 13:23:35 +02:00
|
|
|
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
|
|
|
discard_realm_property_element_changes(elem);
|
|
|
|
}
|
|
|
|
const $save_btn_controls = $subsection.find(".save-button-controls");
|
|
|
|
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function discard_stream_settings_subsection_changes(
|
|
|
|
$subsection: JQuery,
|
|
|
|
sub: StreamSubscription,
|
|
|
|
): void {
|
2024-06-28 13:23:35 +02:00
|
|
|
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
|
|
|
discard_stream_property_element_changes(elem, sub);
|
|
|
|
}
|
|
|
|
const $save_btn_controls = $subsection.find(".save-button-controls");
|
|
|
|
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function discard_group_settings_subsection_changes(
|
|
|
|
$subsection: JQuery,
|
|
|
|
group: UserGroup,
|
|
|
|
): void {
|
2024-06-28 13:23:35 +02:00
|
|
|
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
|
|
|
discard_group_property_element_changes(elem, group);
|
|
|
|
}
|
|
|
|
const $save_btn_controls = $subsection.find(".save-button-controls");
|
|
|
|
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function discard_realm_default_settings_subsection_changes($subsection: JQuery): void {
|
2024-06-28 13:23:35 +02:00
|
|
|
for (const elem of settings_components.get_subsection_property_elements($subsection)) {
|
|
|
|
discard_realm_default_property_element_changes(elem);
|
|
|
|
}
|
|
|
|
const $save_btn_controls = $subsection.find(".save-button-controls");
|
|
|
|
settings_components.change_save_button_state($save_btn_controls, "discarded");
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function deactivate_organization(e: JQuery.Event): void {
|
2022-10-11 14:20:27 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function do_deactivate_realm(): void {
|
2022-10-11 14:20:27 +02:00
|
|
|
channel.post({
|
|
|
|
url: "/json/realm/deactivate",
|
|
|
|
error(xhr) {
|
|
|
|
ui_report.error($t_html({defaultMessage: "Failed"}), xhr, $("#dialog_error"));
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const html_body = render_settings_deactivate_realm_modal();
|
|
|
|
|
|
|
|
dialog_widget.launch({
|
|
|
|
html_heading: $t_html({defaultMessage: "Deactivate organization"}),
|
|
|
|
help_link: "/help/deactivate-your-organization",
|
|
|
|
html_body,
|
|
|
|
on_click: do_deactivate_realm,
|
|
|
|
close_on_submit: false,
|
|
|
|
focus_submit_on_open: true,
|
|
|
|
html_submit_button: $t_html({defaultMessage: "Confirm"}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function sync_realm_settings(property: string): void {
|
2022-11-02 19:39:58 +01:00
|
|
|
if (!meta.loaded) {
|
2018-03-29 13:15:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-09 23:36:58 +02:00
|
|
|
switch (property) {
|
|
|
|
case "emails_restricted_to_domains":
|
|
|
|
case "disallow_disposable_email_addresses":
|
|
|
|
property = "org_join_restrictions";
|
|
|
|
break;
|
2020-07-15 01:29:15 +02:00
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $element = $(`#id_realm_${CSS.escape(property)}`);
|
|
|
|
if ($element.length) {
|
2024-06-18 11:50:51 +02:00
|
|
|
const $subsection = $element.closest(".settings-subsection-parent");
|
|
|
|
if ($subsection.find(".save-button-controls").hasClass("hide")) {
|
2024-10-03 07:13:43 +02:00
|
|
|
discard_realm_property_element_changes(util.the($element));
|
2024-06-18 11:50:51 +02:00
|
|
|
} else {
|
|
|
|
discard_realm_settings_subsection_changes($subsection);
|
|
|
|
}
|
2018-03-29 13:15:50 +02:00
|
|
|
}
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2019-03-07 15:18:10 +01:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function save_organization_settings(
|
|
|
|
data: Record<string, string | number | boolean>,
|
|
|
|
$save_button: JQuery,
|
|
|
|
patch_url: string,
|
|
|
|
success_continuation: (() => void) | undefined,
|
|
|
|
): void {
|
2022-11-03 13:18:42 +01:00
|
|
|
const $subsection_parent = $save_button.closest(".settings-subsection-parent");
|
2022-01-25 11:36:19 +01:00
|
|
|
const $save_btn_container = $subsection_parent.find(".save-button-controls");
|
|
|
|
const $failed_alert_elem = $subsection_parent.find(".subsection-failed-status p");
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_btn_container, "saving");
|
2021-09-28 15:56:47 +02:00
|
|
|
channel.patch({
|
2021-09-29 11:25:28 +02:00
|
|
|
url: patch_url,
|
2021-09-28 15:56:47 +02:00
|
|
|
data,
|
|
|
|
success() {
|
2022-01-25 11:36:19 +01:00
|
|
|
$failed_alert_elem.hide();
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_btn_container, "succeeded");
|
2024-07-18 12:35:07 +02:00
|
|
|
if (success_continuation !== undefined) {
|
|
|
|
success_continuation();
|
|
|
|
}
|
2021-09-28 15:56:47 +02:00
|
|
|
},
|
|
|
|
error(xhr) {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_btn_container, "failed");
|
2022-01-25 11:36:19 +01:00
|
|
|
$save_button.hide();
|
|
|
|
ui_report.error($t_html({defaultMessage: "Save failed"}), xhr, $failed_alert_elem);
|
2021-09-28 15:56:47 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function set_up(): void {
|
2021-02-28 01:20:46 +01:00
|
|
|
build_page();
|
|
|
|
maybe_disable_widgets();
|
|
|
|
}
|
2018-12-08 18:16:37 +01:00
|
|
|
|
2024-07-08 19:00:08 +02:00
|
|
|
function set_up_dropdown_widget(
|
2024-10-03 07:13:43 +02:00
|
|
|
setting_name: keyof Realm,
|
|
|
|
setting_options: () => dropdown_widget.Option[],
|
|
|
|
setting_type: string,
|
|
|
|
): void {
|
2024-06-11 14:02:35 +02:00
|
|
|
const $save_discard_widget_container = $(`#id_${CSS.escape(setting_name)}`).closest(
|
|
|
|
".settings-subsection-parent",
|
|
|
|
);
|
|
|
|
const $events_container = $(`#id_${CSS.escape(setting_name)}`).closest(".settings-section");
|
|
|
|
|
|
|
|
let text_if_current_value_not_in_options;
|
|
|
|
if (setting_type === "channel") {
|
|
|
|
text_if_current_value_not_in_options = $t({defaultMessage: "Cannot view channel"});
|
|
|
|
}
|
|
|
|
|
|
|
|
let unique_id_type = dropdown_widget.DataTypes.NUMBER;
|
|
|
|
if (setting_type === "language") {
|
|
|
|
unique_id_type = dropdown_widget.DataTypes.STRING;
|
|
|
|
}
|
|
|
|
|
|
|
|
const setting_dropdown_widget = new dropdown_widget.DropdownWidget({
|
|
|
|
widget_name: setting_name,
|
|
|
|
get_options: setting_options,
|
|
|
|
$events_container,
|
2024-10-03 07:13:43 +02:00
|
|
|
item_click_callback(event, dropdown, this_widget) {
|
2024-06-11 14:02:35 +02:00
|
|
|
dropdown.hide();
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2024-10-03 07:13:43 +02:00
|
|
|
this_widget.render();
|
2024-06-11 14:02:35 +02:00
|
|
|
settings_components.save_discard_realm_settings_widget_status_handler(
|
|
|
|
$save_discard_widget_container,
|
|
|
|
);
|
|
|
|
},
|
2024-10-03 07:13:43 +02:00
|
|
|
default_id: z.union([z.string(), z.number()]).parse(realm[setting_name]),
|
2024-06-11 14:02:35 +02:00
|
|
|
unique_id_type,
|
2024-10-03 07:13:43 +02:00
|
|
|
...(text_if_current_value_not_in_options && {text_if_current_value_not_in_options}),
|
2024-06-11 14:02:35 +02:00
|
|
|
on_mount_callback(dropdown) {
|
|
|
|
if (setting_type === "group") {
|
|
|
|
$(dropdown.popper).css("min-width", "300px");
|
2024-07-04 16:55:23 +02:00
|
|
|
$(dropdown.popper).find(".simplebar-content").css("width", "max-content");
|
2024-07-19 14:15:35 +02:00
|
|
|
$(dropdown.popper).find(".simplebar-content").css("min-width", "100%");
|
2024-06-11 14:02:35 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
settings_components.set_dropdown_setting_widget(setting_name, setting_dropdown_widget);
|
|
|
|
setting_dropdown_widget.setup();
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function set_up_dropdown_widget_for_realm_group_settings(): void {
|
2024-06-11 14:02:35 +02:00
|
|
|
const realm_group_permission_settings = Object.keys(
|
|
|
|
realm.server_supported_permission_settings.realm,
|
|
|
|
);
|
|
|
|
|
2024-10-28 12:09:28 +01:00
|
|
|
const settings_using_pills_ui = new Set([
|
2024-10-29 11:29:01 +01:00
|
|
|
"can_add_custom_emoji_group",
|
2024-10-28 15:06:21 +01:00
|
|
|
"can_create_groups",
|
2024-10-28 12:09:28 +01:00
|
|
|
"can_create_public_channel_group",
|
|
|
|
"can_create_private_channel_group",
|
2024-10-30 08:15:27 +01:00
|
|
|
"can_delete_any_message_group",
|
|
|
|
"can_delete_own_message_group",
|
2024-10-28 15:06:21 +01:00
|
|
|
"can_manage_all_groups",
|
2024-10-30 07:50:59 +01:00
|
|
|
"can_move_messages_between_channels_group",
|
|
|
|
"can_move_messages_between_topics_group",
|
2024-10-28 12:09:28 +01:00
|
|
|
"create_multiuse_invite_group",
|
2024-10-29 14:29:02 +01:00
|
|
|
"direct_message_initiator_group",
|
|
|
|
"direct_message_permission_group",
|
2024-10-28 12:09:28 +01:00
|
|
|
]);
|
2024-06-11 14:02:35 +02:00
|
|
|
for (const setting_name of realm_group_permission_settings) {
|
2024-10-28 12:09:28 +01:00
|
|
|
if (settings_using_pills_ui.has(setting_name)) {
|
2024-10-27 11:31:15 +01:00
|
|
|
continue;
|
|
|
|
}
|
2024-10-03 07:13:43 +02:00
|
|
|
const get_setting_options = (): UserGroupForDropdownListWidget[] =>
|
2024-06-11 14:02:35 +02:00
|
|
|
user_groups.get_realm_user_groups_for_dropdown_list_widget(setting_name, "realm");
|
2024-07-08 19:00:08 +02:00
|
|
|
set_up_dropdown_widget(
|
2024-10-03 07:13:43 +02:00
|
|
|
realm_schema.keyof().parse("realm_" + setting_name),
|
2024-07-08 19:00:08 +02:00
|
|
|
get_setting_options,
|
|
|
|
"group",
|
|
|
|
);
|
2024-06-11 14:02:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function init_dropdown_widgets(): void {
|
|
|
|
const notification_stream_options = (): dropdown_widget.Option[] => {
|
2023-07-19 16:14:00 +02:00
|
|
|
const streams = stream_settings_data.get_streams_for_settings_page();
|
2024-10-03 07:13:43 +02:00
|
|
|
const options: dropdown_widget.Option[] = streams.map((stream) => ({
|
2023-07-19 16:14:00 +02:00
|
|
|
name: stream.name,
|
|
|
|
unique_id: stream.stream_id,
|
|
|
|
stream,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const disabled_option = {
|
|
|
|
is_setting_disabled: true,
|
|
|
|
unique_id: DISABLED_STATE_ID,
|
2023-11-22 10:53:37 +01:00
|
|
|
name: $t({defaultMessage: "Disabled"}),
|
2023-07-19 16:14:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
options.unshift(disabled_option);
|
|
|
|
return options;
|
2020-04-10 09:38:55 +02:00
|
|
|
};
|
2023-07-19 16:14:00 +02:00
|
|
|
|
2024-06-11 14:02:35 +02:00
|
|
|
set_up_dropdown_widget(
|
2024-06-11 14:01:39 +02:00
|
|
|
"realm_new_stream_announcements_stream_id",
|
2024-06-11 14:02:35 +02:00
|
|
|
notification_stream_options,
|
|
|
|
"channel",
|
2024-02-07 12:13:02 +01:00
|
|
|
);
|
2024-06-11 14:02:35 +02:00
|
|
|
set_up_dropdown_widget(
|
2024-06-11 14:01:39 +02:00
|
|
|
"realm_signup_announcements_stream_id",
|
2024-06-11 14:02:35 +02:00
|
|
|
notification_stream_options,
|
|
|
|
"channel",
|
2024-06-11 14:01:39 +02:00
|
|
|
);
|
2024-06-11 14:02:35 +02:00
|
|
|
set_up_dropdown_widget(
|
2024-06-11 14:01:39 +02:00
|
|
|
"realm_zulip_update_announcements_stream_id",
|
2024-06-11 14:02:35 +02:00
|
|
|
notification_stream_options,
|
|
|
|
"channel",
|
2024-01-26 14:45:37 +01:00
|
|
|
);
|
2024-06-11 14:02:35 +02:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
const default_code_language_options = (): dropdown_widget.Option[] => {
|
2024-06-11 14:02:35 +02:00
|
|
|
const options = Object.keys(pygments_data.langs).map((x) => ({
|
|
|
|
name: x,
|
|
|
|
unique_id: x,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const disabled_option = {
|
|
|
|
is_setting_disabled: true,
|
|
|
|
unique_id: "",
|
|
|
|
name: $t({defaultMessage: "No language set"}),
|
|
|
|
};
|
|
|
|
|
|
|
|
options.unshift(disabled_option);
|
|
|
|
return options;
|
|
|
|
};
|
|
|
|
set_up_dropdown_widget(
|
2024-06-11 14:01:39 +02:00
|
|
|
"realm_default_code_block_language",
|
2024-06-11 14:02:35 +02:00
|
|
|
default_code_language_options,
|
|
|
|
"language",
|
2024-06-11 14:01:39 +02:00
|
|
|
);
|
2024-06-11 14:02:35 +02:00
|
|
|
|
|
|
|
set_up_dropdown_widget_for_realm_group_settings();
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|
2020-04-10 04:43:37 +02:00
|
|
|
|
2021-09-28 09:09:52 +02:00
|
|
|
export function register_save_discard_widget_handlers(
|
2024-10-03 07:13:43 +02:00
|
|
|
$container: JQuery,
|
|
|
|
patch_url: string,
|
|
|
|
for_realm_default_settings: boolean,
|
|
|
|
): void {
|
|
|
|
$container.on("change input", "input, select, textarea", function (this: HTMLElement, 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
|
|
|
|
2024-10-07 08:08:20 +02:00
|
|
|
if ($(this).hasClass("no-input-change-detection")) {
|
2019-08-05 21:11:30 +02:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2024-10-07 08:08:20 +02:00
|
|
|
if ($(this).hasClass("setting_email_notifications_batching_period_seconds")) {
|
|
|
|
const show_elem = $(this).val() === "custom_period";
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2021-12-02 15:56:34 +01:00
|
|
|
"realm_email_notification_batching_period_edit_minutes",
|
|
|
|
show_elem,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-10-07 08:08:20 +02:00
|
|
|
const $subsection = $(this).closest(".settings-subsection-parent");
|
2024-05-20 21:36:38 +02:00
|
|
|
if (for_realm_default_settings) {
|
|
|
|
settings_components.save_discard_default_realm_settings_widget_status_handler(
|
|
|
|
$subsection,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
settings_components.save_discard_realm_settings_widget_status_handler($subsection);
|
|
|
|
}
|
|
|
|
|
2020-09-24 07:50:36 +02:00
|
|
|
return undefined;
|
2018-03-14 23:50:17 +01:00
|
|
|
});
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
$container.on(
|
|
|
|
"click",
|
|
|
|
".subsection-header .subsection-changes-discard button",
|
|
|
|
function (this: HTMLElement, e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
const $subsection = $(this).closest(".settings-subsection-parent");
|
|
|
|
if (for_realm_default_settings) {
|
|
|
|
discard_realm_default_settings_subsection_changes($subsection);
|
|
|
|
} else {
|
|
|
|
discard_realm_settings_subsection_changes($subsection);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2018-03-14 23:52:36 +01:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
$container.on(
|
|
|
|
"click",
|
|
|
|
".subsection-header .subsection-changes-save button",
|
|
|
|
function (this: HTMLElement, e: JQuery.ClickEvent) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
const $save_button = $(this);
|
|
|
|
const $subsection_elem = $save_button.closest(".settings-subsection-parent");
|
|
|
|
let data: Record<string, string | number | boolean>;
|
|
|
|
let success_continuation;
|
|
|
|
if (!for_realm_default_settings) {
|
|
|
|
data =
|
|
|
|
settings_components.populate_data_for_realm_settings_request($subsection_elem);
|
|
|
|
} else {
|
|
|
|
data =
|
|
|
|
settings_components.populate_data_for_default_realm_settings_request(
|
|
|
|
$subsection_elem,
|
2024-07-18 12:35:07 +02:00
|
|
|
);
|
2024-10-03 07:13:43 +02:00
|
|
|
|
|
|
|
if (
|
|
|
|
data.dense_mode !== undefined ||
|
|
|
|
data.web_font_size_px !== undefined ||
|
|
|
|
data.web_line_height_percent !== undefined
|
|
|
|
) {
|
|
|
|
success_continuation = () => {
|
|
|
|
settings_preferences.update_information_density_settings_visibility(
|
|
|
|
$("#realm-user-default-settings"),
|
|
|
|
realm_user_settings_defaults,
|
|
|
|
data,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
2024-07-18 12:35:07 +02:00
|
|
|
}
|
2024-10-03 07:13:43 +02:00
|
|
|
save_organization_settings(data, $save_button, patch_url, success_continuation);
|
|
|
|
},
|
|
|
|
);
|
2021-09-29 13:03:35 +02:00
|
|
|
}
|
|
|
|
|
2024-10-27 11:31:15 +01:00
|
|
|
function initialize_group_setting_widgets(): void {
|
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_create_multiuse_invite_group"),
|
|
|
|
setting_name: "create_multiuse_invite_group",
|
|
|
|
});
|
2024-10-28 12:09:28 +01:00
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_create_public_channel_group"),
|
|
|
|
setting_name: "can_create_public_channel_group",
|
|
|
|
});
|
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_create_private_channel_group"),
|
|
|
|
setting_name: "can_create_private_channel_group",
|
|
|
|
});
|
2024-10-28 15:06:21 +01:00
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_create_groups"),
|
|
|
|
setting_name: "can_create_groups",
|
|
|
|
});
|
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_manage_all_groups"),
|
|
|
|
setting_name: "can_manage_all_groups",
|
|
|
|
});
|
2024-10-29 14:29:02 +01:00
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_direct_message_initiator_group"),
|
|
|
|
setting_name: "direct_message_initiator_group",
|
|
|
|
});
|
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_direct_message_permission_group"),
|
|
|
|
setting_name: "direct_message_permission_group",
|
|
|
|
pill_update_callback: check_disable_direct_message_initiator_group_widget,
|
|
|
|
});
|
2024-10-29 11:29:01 +01:00
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_add_custom_emoji_group"),
|
|
|
|
setting_name: "can_add_custom_emoji_group",
|
|
|
|
});
|
2024-10-30 07:50:59 +01:00
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_move_messages_between_channels_group"),
|
|
|
|
setting_name: "can_move_messages_between_channels_group",
|
|
|
|
});
|
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_move_messages_between_topics_group"),
|
|
|
|
setting_name: "can_move_messages_between_topics_group",
|
|
|
|
});
|
2024-10-30 08:15:27 +01:00
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_delete_any_message_group"),
|
|
|
|
setting_name: "can_delete_any_message_group",
|
|
|
|
});
|
|
|
|
settings_components.create_realm_group_setting_widget({
|
|
|
|
$pill_container: $("#id_realm_can_delete_own_message_group"),
|
|
|
|
setting_name: "can_delete_own_message_group",
|
|
|
|
});
|
2024-10-27 11:31:15 +01:00
|
|
|
|
|
|
|
enable_or_disable_group_permission_settings();
|
2024-10-29 14:29:02 +01:00
|
|
|
check_disable_direct_message_initiator_group_widget();
|
2024-10-27 11:31:15 +01:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
export function build_page(): void {
|
2021-09-29 13:03:35 +02:00
|
|
|
meta.loaded = true;
|
|
|
|
|
|
|
|
loading.make_indicator($("#admin_page_auth_methods_loading_indicator"));
|
|
|
|
|
|
|
|
// Initialize all the dropdown list widgets.
|
|
|
|
init_dropdown_widgets();
|
|
|
|
// Populate realm domains
|
2024-02-13 02:08:24 +01:00
|
|
|
populate_realm_domains_label(realm.realm_domains);
|
2021-09-29 13:03:35 +02:00
|
|
|
|
2024-10-27 11:31:15 +01:00
|
|
|
initialize_group_setting_widgets();
|
|
|
|
|
2021-09-29 13:03:35 +02:00
|
|
|
// Populate authentication methods table
|
2024-02-05 23:52:25 +01:00
|
|
|
|
|
|
|
populate_auth_methods(settings_components.realm_authentication_methods_to_boolean_dict());
|
2021-09-29 13:03:35 +02:00
|
|
|
|
|
|
|
for (const property_name of simple_dropdown_properties) {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.set_property_dropdown_value(property_name);
|
2021-09-29 13:03:35 +02:00
|
|
|
}
|
|
|
|
|
2022-12-12 18:21:08 +01:00
|
|
|
set_realm_waiting_period_setting();
|
2021-09-29 13:03:35 +02:00
|
|
|
set_video_chat_provider_dropdown();
|
|
|
|
set_giphy_rating_dropdown();
|
|
|
|
set_msg_edit_limit_dropdown();
|
2022-12-22 19:14:23 +01:00
|
|
|
set_msg_move_limit_setting("realm_move_messages_within_stream_limit_seconds");
|
2023-01-30 12:15:36 +01:00
|
|
|
set_msg_move_limit_setting("realm_move_messages_between_streams_limit_seconds");
|
2021-09-29 13:03:35 +02:00
|
|
|
set_msg_delete_limit_dropdown();
|
2024-10-07 08:17:48 +02:00
|
|
|
set_message_retention_setting_dropdown(undefined);
|
2021-09-29 13:03:35 +02:00
|
|
|
set_org_join_restrictions_dropdown();
|
2023-01-02 20:50:23 +01:00
|
|
|
set_message_content_in_email_notifications_visibility();
|
2021-09-29 13:03:35 +02:00
|
|
|
set_digest_emails_weekday_visibility();
|
2021-11-19 10:29:39 +01:00
|
|
|
set_create_web_public_stream_dropdown_visibility();
|
2021-09-29 13:03:35 +02:00
|
|
|
|
2021-09-28 09:09:52 +02:00
|
|
|
register_save_discard_widget_handlers($(".admin-realm-form"), "/json/realm", false);
|
2017-08-18 01:23:55 +02:00
|
|
|
|
2022-11-03 13:18:42 +01:00
|
|
|
$(".settings-subsection-parent").on("keydown", "input", (e) => {
|
2018-03-22 14:16:53 +01:00
|
|
|
e.stopPropagation();
|
2022-09-28 08:27:24 +02:00
|
|
|
if (keydown_util.is_enter_event(e)) {
|
2018-03-22 14:16:53 +01:00
|
|
|
e.preventDefault();
|
2020-07-15 00:34:28 +02:00
|
|
|
$(e.target)
|
2022-11-03 13:18:42 +01:00
|
|
|
.closest(".settings-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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-09-02 13:58:03 +02:00
|
|
|
$("#id_realm_message_content_edit_limit_seconds").on("change", () => {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.update_custom_value_input("realm_message_content_edit_limit_seconds");
|
2018-04-02 11:18:40 +02:00
|
|
|
});
|
|
|
|
|
2023-01-30 12:15:36 +01:00
|
|
|
$("#id_realm_move_messages_between_streams_limit_seconds").on("change", () => {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.update_custom_value_input(
|
|
|
|
"realm_move_messages_between_streams_limit_seconds",
|
|
|
|
);
|
2023-01-30 12:15:36 +01:00
|
|
|
});
|
|
|
|
|
2022-12-22 19:14:23 +01:00
|
|
|
$("#id_realm_move_messages_within_stream_limit_seconds").on("change", () => {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.update_custom_value_input(
|
|
|
|
"realm_move_messages_within_stream_limit_seconds",
|
|
|
|
);
|
2022-12-22 19:14:23 +01:00
|
|
|
});
|
|
|
|
|
2022-09-02 13:58:03 +02:00
|
|
|
$("#id_realm_message_content_delete_limit_seconds").on("change", () => {
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.update_custom_value_input("realm_message_content_delete_limit_seconds");
|
2017-11-26 09:12:10 +01:00
|
|
|
});
|
|
|
|
|
2023-09-19 18:10:23 +02:00
|
|
|
$("#id_realm_video_chat_provider").on("change", () => {
|
|
|
|
set_jitsi_server_url_dropdown();
|
|
|
|
});
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
$<HTMLSelectOneElement>("select:not([multiple])#id_realm_jitsi_server_url").on(
|
|
|
|
"change",
|
|
|
|
function () {
|
|
|
|
const dropdown_val = this.value;
|
|
|
|
update_jitsi_server_url_custom_input(dropdown_val);
|
|
|
|
},
|
|
|
|
);
|
2023-09-19 18:10:23 +02:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
$<HTMLSelectOneElement>("select:not([multiple])#id_realm_message_retention_days").on(
|
|
|
|
"change",
|
|
|
|
function () {
|
|
|
|
const message_retention_setting_dropdown_value = this.value;
|
|
|
|
settings_components.change_element_block_display_property(
|
|
|
|
"id_realm_message_retention_custom_input",
|
|
|
|
message_retention_setting_dropdown_value === "custom_period",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2020-05-07 13:19:54 +02:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
$<HTMLSelectOneElement>("select:not([multiple])#id_realm_waiting_period_threshold").on(
|
|
|
|
"change",
|
|
|
|
function () {
|
|
|
|
const waiting_period_threshold = this.value;
|
|
|
|
settings_components.change_element_block_display_property(
|
|
|
|
"id_realm_waiting_period_threshold_custom_input",
|
|
|
|
waiting_period_threshold === "custom_period",
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2018-01-05 15:34:10 +01:00
|
|
|
|
2024-10-07 08:08:20 +02:00
|
|
|
$("#id_realm_digest_emails_enabled").on("change", function () {
|
|
|
|
const digest_emails_enabled = $(this).is(":checked");
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_element_block_display_property(
|
2022-02-20 12:06:19 +01:00
|
|
|
"id_realm_digest_weekday",
|
2024-10-03 07:13:43 +02:00
|
|
|
digest_emails_enabled,
|
2022-02-20 12:06:19 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
$<HTMLSelectOneElement>("select:not([multiple])#id_realm_org_join_restrictions").on(
|
|
|
|
"change",
|
|
|
|
function () {
|
|
|
|
const org_join_restrictions = this.value;
|
|
|
|
const $node = $("#allowed_domains_label").parent();
|
|
|
|
if (org_join_restrictions === "only_selected_domain") {
|
|
|
|
$node.show();
|
|
|
|
if (realm.realm_domains.length === 0) {
|
|
|
|
settings_realm_domains.show_realm_domains_modal();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$node.hide();
|
2018-04-05 00:54:31 +02:00
|
|
|
}
|
2024-10-03 07:13:43 +02:00
|
|
|
},
|
|
|
|
);
|
2018-04-05 00:54:31 +02:00
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
$<HTMLInputElement>("input#id_realm_allow_message_editing").on("change", function () {
|
|
|
|
update_message_edit_sub_settings(this.checked);
|
2022-04-12 09:56:58 +02:00
|
|
|
});
|
|
|
|
|
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();
|
|
|
|
});
|
|
|
|
|
2021-07-20 14:51:48 +02:00
|
|
|
$("#show_realm_domains_modal").on("click", (e) => {
|
2017-04-08 18:13:39 +02:00
|
|
|
e.stopPropagation();
|
2021-07-20 14:51:48 +02:00
|
|
|
settings_realm_domains.show_realm_domains_modal();
|
2017-04-08 18:13:39 +02:00
|
|
|
});
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function realm_icon_logo_upload_complete(
|
|
|
|
$spinner: JQuery,
|
|
|
|
$upload_text: JQuery,
|
|
|
|
$delete_button: JQuery,
|
|
|
|
): void {
|
2022-01-25 11:36:19 +01:00
|
|
|
$spinner.css({visibility: "hidden"});
|
|
|
|
$upload_text.show();
|
|
|
|
$delete_button.show();
|
2020-05-27 14:16:04 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function realm_icon_logo_upload_start(
|
|
|
|
$spinner: JQuery,
|
|
|
|
$upload_text: JQuery,
|
|
|
|
$delete_button: JQuery,
|
|
|
|
): void {
|
2022-01-25 11:36:19 +01:00
|
|
|
$spinner.css({visibility: "visible"});
|
|
|
|
$upload_text.hide();
|
|
|
|
$delete_button.hide();
|
2020-05-27 14:16:04 +02:00
|
|
|
}
|
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
function upload_realm_logo_or_icon(
|
|
|
|
$file_input: JQuery<HTMLInputElement>,
|
|
|
|
night: boolean | null,
|
|
|
|
icon: boolean,
|
|
|
|
): void {
|
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
|
|
|
|
2024-10-03 07:13:43 +02:00
|
|
|
assert(csrf_token !== undefined);
|
2020-07-15 01:29:15 +02:00
|
|
|
form_data.append("csrfmiddlewaretoken", csrf_token);
|
2024-10-03 07:13:43 +02:00
|
|
|
const files = util.the($file_input).files;
|
|
|
|
assert(files !== null);
|
|
|
|
for (const [i, file] of [...files].entries()) {
|
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
|
|
|
}
|
2022-01-25 11:36:19 +01:00
|
|
|
const $spinner = $(`${widget} .upload-spinner-background`).expectOne();
|
|
|
|
const $upload_text = $(`${widget} .image-upload-text`).expectOne();
|
|
|
|
const $delete_button = $(`${widget} .image-delete-button`).expectOne();
|
|
|
|
const $error_field = $(`${widget} .image_file_input_error`).expectOne();
|
|
|
|
realm_icon_logo_upload_start($spinner, $upload_text, $delete_button);
|
|
|
|
$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() {
|
2022-01-25 11:36:19 +01: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) {
|
2022-01-25 11:36:19 +01:00
|
|
|
realm_icon_logo_upload_complete($spinner, $upload_text, $delete_button);
|
|
|
|
ui_report.error("", xhr, $error_field);
|
2018-08-16 01:26:55 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2019-02-27 15:45:26 +01:00
|
|
|
|
2024-10-07 08:18:48 +02:00
|
|
|
realm_icon.build_realm_icon_widget(upload_realm_logo_or_icon);
|
2024-02-13 02:08:24 +01:00
|
|
|
if (realm.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
|
|
|
|
2022-10-11 14:20:27 +02:00
|
|
|
$("#organization-profile .deactivate_realm_button").on("click", deactivate_organization);
|
2021-02-28 01:20:46 +01:00
|
|
|
}
|