2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2024-11-13 07:05:32 +01:00
|
|
|
const {$t} = require("./lib/i18n.cjs");
|
|
|
|
const {mock_esm, set_global, zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test, noop} = require("./lib/test.cjs");
|
|
|
|
const $ = require("./lib/zjquery.cjs");
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const realm_icon = mock_esm("../src/realm_icon");
|
2021-02-28 00:39:51 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const channel = mock_esm("../src/channel");
|
2021-02-28 01:03:46 +01:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/csrf", {csrf_token: "token-stub"});
|
|
|
|
mock_esm("../src/loading", {
|
2021-03-07 13:57:14 +01:00
|
|
|
make_indicator: noop,
|
|
|
|
destroy_indicator: noop,
|
|
|
|
});
|
2024-03-13 20:23:02 +01:00
|
|
|
mock_esm("../src/scroll_util", {scroll_element_into_container: noop});
|
2024-04-09 18:41:25 +02:00
|
|
|
set_global("document", "document-stub");
|
2020-04-15 04:29:15 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const settings_config = zrequire("settings_config");
|
|
|
|
const settings_bots = zrequire("settings_bots");
|
2021-02-24 22:31:50 +01:00
|
|
|
const settings_account = zrequire("settings_account");
|
2023-10-09 23:29:16 +02:00
|
|
|
const settings_components = zrequire("settings_components");
|
2021-02-10 04:53:22 +01:00
|
|
|
const settings_org = zrequire("settings_org");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_current_user, set_realm} = zrequire("state_data");
|
2024-10-09 08:44:21 +02:00
|
|
|
const {initialize_user_settings} = zrequire("user_settings");
|
|
|
|
|
2024-10-09 22:44:13 +02:00
|
|
|
const current_user = {};
|
|
|
|
set_current_user(current_user);
|
|
|
|
const realm = {};
|
|
|
|
set_realm(realm);
|
2024-10-09 08:44:21 +02:00
|
|
|
initialize_user_settings({user_settings: {}});
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2021-03-14 14:08:11 +01:00
|
|
|
function test(label, f) {
|
2022-07-10 01:06:33 +02:00
|
|
|
run_test(label, (helpers) => {
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#realm-icon-upload-widget .upload-spinner-background").css = noop;
|
2024-10-09 21:21:41 +02:00
|
|
|
helpers.override(current_user, "is_admin", false);
|
2024-10-10 00:50:57 +02:00
|
|
|
helpers.override(realm, "realm_domains", [
|
2021-03-25 22:35:45 +01:00
|
|
|
{domain: "example.com", allow_subdomains: true},
|
|
|
|
{domain: "example.org", allow_subdomains: false},
|
2024-10-10 00:50:57 +02:00
|
|
|
]);
|
2024-10-09 22:20:06 +02:00
|
|
|
helpers.override(realm, "realm_authentication_methods", {});
|
2021-03-14 14:08:11 +01:00
|
|
|
settings_org.reset();
|
2022-07-10 01:06:33 +02:00
|
|
|
f(helpers);
|
2021-03-14 14:08:11 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test("unloaded", () => {
|
2018-08-01 21:17:03 +02:00
|
|
|
// This test mostly gets us line coverage, and makes
|
|
|
|
// sure things don't explode before set_up is called.
|
|
|
|
|
|
|
|
settings_org.reset();
|
2021-07-20 14:51:48 +02:00
|
|
|
settings_org.populate_realm_domains_label();
|
2018-08-01 21:17:03 +02:00
|
|
|
settings_org.populate_auth_methods();
|
2017-06-16 14:41:10 +02:00
|
|
|
});
|
|
|
|
|
2018-04-16 18:58:27 +02:00
|
|
|
function createSaveButtons(subsection) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stub_save_button_header = $(`#org-${CSS.escape(subsection)}`);
|
|
|
|
const $save_button_controls = $(".save-button-controls");
|
2022-12-07 12:16:37 +01:00
|
|
|
const $stub_save_button = $(".save-discard-widget-button.save-button");
|
2022-12-07 13:17:29 +01:00
|
|
|
const $stub_discard_button = $(".save-discard-widget-button.discard-button");
|
2022-01-25 11:36:19 +01:00
|
|
|
const $stub_save_button_text = $(".save-discard-widget-button-text");
|
|
|
|
$stub_save_button_header.set_find_results(
|
2020-07-15 00:34:28 +02:00
|
|
|
".subsection-failed-status p",
|
2022-03-17 00:31:13 +01:00
|
|
|
$("<failed-status-stub>"),
|
2018-04-30 15:27:35 +02:00
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
$stub_save_button.closest = () => $stub_save_button_header;
|
|
|
|
$save_button_controls.set_find_results(".save-button", $stub_save_button);
|
|
|
|
$stub_save_button.set_find_results(".save-discard-widget-button-text", $stub_save_button_text);
|
|
|
|
$stub_save_button_header.set_find_results(".save-button-controls", $save_button_controls);
|
|
|
|
$stub_save_button_header.set_find_results(
|
2021-06-03 18:15:17 +02:00
|
|
|
".subsection-changes-discard button",
|
2022-12-07 13:17:29 +01:00
|
|
|
$stub_discard_button,
|
2019-03-07 15:18:10 +01:00
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
$save_button_controls.set_find_results(".discard-button", $stub_discard_button);
|
2020-07-16 23:29:01 +02:00
|
|
|
const props = {};
|
2018-03-29 02:02:01 +02:00
|
|
|
props.hidden = false;
|
2022-01-25 11:36:19 +01:00
|
|
|
$save_button_controls.fadeIn = () => {
|
2018-05-07 03:30:13 +02:00
|
|
|
props.hidden = false;
|
2018-04-30 15:01:55 +02:00
|
|
|
};
|
2022-01-25 11:36:19 +01:00
|
|
|
$save_button_controls.fadeOut = () => {
|
2018-04-30 15:01:55 +02:00
|
|
|
props.hidden = true;
|
2018-03-29 02:02:01 +02:00
|
|
|
};
|
2022-09-15 13:22:47 +02:00
|
|
|
|
|
|
|
$save_button_controls.closest = () => $stub_save_button_header;
|
|
|
|
$stub_save_button_header.set_find_results(".time-limit-setting", []);
|
2024-10-29 11:01:43 +01:00
|
|
|
$stub_save_button_header.set_find_results(".pill-container", []);
|
2022-09-15 13:22:47 +02:00
|
|
|
$stub_save_button_header.set_find_results(".subsection-changes-save button", $stub_save_button);
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
return {
|
2020-07-20 22:18:43 +02:00
|
|
|
props,
|
2022-01-25 11:36:19 +01:00
|
|
|
$save_button: $stub_save_button,
|
|
|
|
$discard_button: $stub_discard_button,
|
|
|
|
$save_button_header: $stub_save_button_header,
|
|
|
|
$save_button_controls,
|
|
|
|
$save_button_text: $stub_save_button_text,
|
2018-03-29 02:02:01 +02:00
|
|
|
};
|
|
|
|
}
|
2018-04-16 18:58:27 +02:00
|
|
|
|
2021-03-14 14:08:11 +01:00
|
|
|
function test_submit_settings_form(override, submit_form) {
|
2024-02-13 02:08:24 +01:00
|
|
|
Object.assign(realm, {
|
2020-04-01 08:30:41 +02:00
|
|
|
realm_bot_creation_policy: settings_bots.bot_creation_policy_values.restricted.code,
|
2019-05-05 15:49:37 +02:00
|
|
|
realm_waiting_period_threshold: 1,
|
|
|
|
realm_default_language: '"es"',
|
2021-04-28 20:39:24 +02:00
|
|
|
realm_invite_to_stream_policy: settings_config.common_policy_values.by_admins_only.code,
|
2021-05-23 21:40:20 +02:00
|
|
|
realm_invite_to_realm_policy: settings_config.common_policy_values.by_members.code,
|
2019-05-05 15:49:37 +02:00
|
|
|
});
|
|
|
|
|
2021-03-14 14:08:11 +01:00
|
|
|
override(global, "setTimeout", (func) => func());
|
2018-04-16 18:58:27 +02:00
|
|
|
const ev = {
|
2017-06-16 14:41:10 +02:00
|
|
|
preventDefault: noop,
|
|
|
|
stopPropagation: noop,
|
|
|
|
};
|
|
|
|
|
2018-04-16 18:58:27 +02:00
|
|
|
let patched;
|
|
|
|
let data;
|
|
|
|
let success_callback;
|
2021-03-14 14:08:11 +01:00
|
|
|
override(channel, "patch", (req) => {
|
2017-06-16 14:41:10 +02:00
|
|
|
patched = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(req.url, "/json/realm");
|
2018-04-16 18:58:27 +02:00
|
|
|
data = req.data;
|
2017-06-16 14:41:10 +02:00
|
|
|
success_callback = req.success;
|
2021-03-14 14:08:11 +01:00
|
|
|
});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
let subsection = "other-permissions";
|
2019-03-06 17:24:14 +01:00
|
|
|
let stubs = createSaveButtons(subsection);
|
2022-01-25 11:36:19 +01:00
|
|
|
let $save_button = stubs.$save_button;
|
2022-12-07 12:16:37 +01:00
|
|
|
let $save_button_header = stubs.$save_button_header;
|
|
|
|
$save_button_header.attr("id", `org-${subsection}`);
|
2020-01-23 07:01:34 +01:00
|
|
|
|
2019-05-07 19:06:05 +02:00
|
|
|
$("#id_realm_waiting_period_threshold").val(10);
|
2019-05-05 15:13:52 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $invite_to_stream_policy_elem = $("#id_realm_invite_to_stream_policy");
|
|
|
|
$invite_to_stream_policy_elem.val("1");
|
|
|
|
$invite_to_stream_policy_elem.attr("id", "id_realm_invite_to_stream_policy");
|
|
|
|
$invite_to_stream_policy_elem.data = () => "number";
|
|
|
|
|
|
|
|
const $bot_creation_policy_elem = $("#id_realm_bot_creation_policy");
|
|
|
|
$bot_creation_policy_elem.val("1");
|
|
|
|
$bot_creation_policy_elem.attr("id", "id_realm_bot_creation_policy");
|
|
|
|
$bot_creation_policy_elem.data = () => "number";
|
|
|
|
|
|
|
|
const $invite_to_realm_policy_elem = $("#id_realm_invite_to_realm_policy");
|
|
|
|
$invite_to_realm_policy_elem.val("2");
|
|
|
|
$invite_to_realm_policy_elem.attr("id", "id_realm_invite_to_realm_policy");
|
|
|
|
$invite_to_realm_policy_elem.data = () => "number";
|
|
|
|
|
|
|
|
let $subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
|
|
|
$subsection_elem.set_find_results(".prop-element", [
|
|
|
|
$bot_creation_policy_elem,
|
2022-04-09 23:44:38 +02:00
|
|
|
$invite_to_realm_policy_elem,
|
2022-01-25 11:36:19 +01:00
|
|
|
$invite_to_stream_policy_elem,
|
2019-03-06 17:24:14 +01:00
|
|
|
]);
|
2018-03-14 23:45:42 +01:00
|
|
|
|
2018-06-16 13:21:59 +02:00
|
|
|
patched = false;
|
2024-10-07 08:08:20 +02:00
|
|
|
submit_form.call({to_$: () => $(".save-discard-widget-button.save-button")}, ev);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(patched);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2018-04-16 18:58:27 +02:00
|
|
|
let expected_value = {
|
2021-04-07 22:00:40 +02:00
|
|
|
bot_creation_policy: 1,
|
2022-04-09 23:44:38 +02:00
|
|
|
invite_to_realm_policy: 2,
|
2021-04-07 22:00:40 +02:00
|
|
|
invite_to_stream_policy: 1,
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
2018-04-16 18:58:27 +02:00
|
|
|
assert.deepEqual(data, expected_value);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
subsection = "user-defaults";
|
2019-03-06 17:24:14 +01:00
|
|
|
stubs = createSaveButtons(subsection);
|
2022-01-25 11:36:19 +01:00
|
|
|
$save_button = stubs.$save_button;
|
2022-12-07 12:16:37 +01:00
|
|
|
$save_button_header = stubs.$save_button_header;
|
|
|
|
$save_button_header.attr("id", `org-${subsection}`);
|
2019-03-06 17:24:14 +01:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $realm_default_language_elem = $("#id_realm_default_language");
|
|
|
|
$realm_default_language_elem.val("en");
|
|
|
|
$realm_default_language_elem.attr("id", "id_realm_default_language");
|
|
|
|
$realm_default_language_elem.data = () => "string";
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$subsection_elem = $(`#org-${CSS.escape(subsection)}`);
|
|
|
|
$subsection_elem.set_find_results(".prop-element", [$realm_default_language_elem]);
|
2018-04-16 18:58:27 +02:00
|
|
|
|
2024-10-07 08:08:20 +02:00
|
|
|
submit_form.call({to_$: () => $(".save-discard-widget-button.save-button")}, ev);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(patched);
|
2018-04-16 18:58:27 +02:00
|
|
|
|
|
|
|
expected_value = {
|
2021-04-07 22:00:40 +02:00
|
|
|
default_language: "en",
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
2018-04-16 18:58:27 +02:00
|
|
|
assert.deepEqual(data, expected_value);
|
|
|
|
|
|
|
|
// Testing only once for since callback is same for all cases
|
|
|
|
success_callback();
|
|
|
|
assert.equal(stubs.props.hidden, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button.attr("data-status"), "saved");
|
|
|
|
assert.equal(stubs.$save_button_text.text(), "translated: Saved");
|
2017-08-18 01:23:55 +02:00
|
|
|
}
|
|
|
|
|
2018-03-29 02:02:01 +02:00
|
|
|
function test_change_save_button_state() {
|
2022-12-07 12:16:37 +01:00
|
|
|
const {
|
|
|
|
$save_button_controls,
|
|
|
|
$save_button_text,
|
|
|
|
$save_button,
|
|
|
|
$save_button_header,
|
|
|
|
$discard_button,
|
|
|
|
props,
|
|
|
|
} = createSaveButtons("msg-editing");
|
|
|
|
$save_button_header.attr("id", "org-msg-editing");
|
2019-03-10 09:00:30 +01:00
|
|
|
|
|
|
|
{
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_button_controls, "unsaved");
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button_text.text(), "translated: Save changes");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(props.hidden, false);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button.attr("data-status"), "unsaved");
|
|
|
|
assert.equal($discard_button.visible(), true);
|
2019-03-10 09:00:30 +01:00
|
|
|
}
|
|
|
|
{
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_button_controls, "saved");
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button_text.text(), "translated: Save changes");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(props.hidden, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button.attr("data-status"), "");
|
2019-03-10 09:00:30 +01:00
|
|
|
}
|
|
|
|
{
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_button_controls, "saving");
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button_text.text(), "translated: Saving");
|
|
|
|
assert.equal($save_button.attr("data-status"), "saving");
|
|
|
|
assert.equal($save_button.hasClass("saving"), true);
|
|
|
|
assert.equal($discard_button.visible(), false);
|
2019-03-10 09:00:30 +01:00
|
|
|
}
|
|
|
|
{
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_button_controls, "discarded");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(props.hidden, true);
|
|
|
|
}
|
|
|
|
{
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_button_controls, "succeeded");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(props.hidden, true);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button.attr("data-status"), "saved");
|
|
|
|
assert.equal($save_button_text.text(), "translated: Saved");
|
2019-03-10 09:00:30 +01:00
|
|
|
}
|
|
|
|
{
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.change_save_button_state($save_button_controls, "failed");
|
2019-03-10 09:00:30 +01:00
|
|
|
assert.equal(props.hidden, false);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($save_button.attr("data-status"), "failed");
|
|
|
|
assert.equal($save_button_text.text(), "translated: Save changes");
|
2019-03-10 09:00:30 +01:00
|
|
|
}
|
2018-03-29 02:02:01 +02:00
|
|
|
}
|
|
|
|
|
2021-03-14 14:08:11 +01:00
|
|
|
function test_upload_realm_icon(override, upload_realm_logo_or_icon) {
|
2020-07-15 00:34:28 +02:00
|
|
|
const file_input = [{files: ["image1.png", "image2.png"]}];
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let posted;
|
2021-03-14 14:08:11 +01:00
|
|
|
override(channel, "post", (req) => {
|
2017-06-16 14:41:10 +02:00
|
|
|
posted = true;
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(req.url, "/json/realm/icon");
|
2022-08-18 03:01:28 +02:00
|
|
|
assert.equal(req.data.get("csrfmiddlewaretoken"), "token-stub");
|
|
|
|
assert.equal(req.data.get("file-0"), "image1.png");
|
|
|
|
assert.equal(req.data.get("file-1"), "image2.png");
|
2021-03-14 14:08:11 +01:00
|
|
|
});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-06-11 01:04:12 +02:00
|
|
|
upload_realm_logo_or_icon(file_input, null, true);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(posted);
|
2017-06-16 14:41:10 +02:00
|
|
|
}
|
|
|
|
|
2018-03-14 23:50:17 +01:00
|
|
|
function test_extract_property_name() {
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#id_realm_allow_message_editing").attr("id", "id_realm_allow_message_editing");
|
2018-03-14 23:50:17 +01:00
|
|
|
assert.equal(
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.extract_property_name($("#id_realm_allow_message_editing")),
|
2020-07-15 01:29:15 +02:00
|
|
|
"realm_allow_message_editing",
|
2018-03-14 23:50:17 +01:00
|
|
|
);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#id_realm_message_content_edit_limit_minutes_label").attr(
|
2020-07-15 00:34:28 +02:00
|
|
|
"id",
|
|
|
|
"id_realm_message_content_edit_limit_minutes_label",
|
|
|
|
);
|
2018-03-14 23:50:17 +01:00
|
|
|
assert.equal(
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.extract_property_name(
|
|
|
|
$("#id_realm_message_content_edit_limit_minutes_label"),
|
|
|
|
),
|
2020-07-15 01:29:15 +02:00
|
|
|
"realm_message_content_edit_limit_minutes_label",
|
2018-03-14 23:50:17 +01:00
|
|
|
);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#id-realm-allow-message-deleting").attr("id", "id-realm-allow-message-deleting");
|
2018-03-14 23:50:17 +01:00
|
|
|
assert.equal(
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.extract_property_name($("#id-realm-allow-message-deleting")),
|
2020-07-15 01:29:15 +02:00
|
|
|
"realm_allow_message_deleting",
|
2018-03-14 23:50:17 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
function test_sync_realm_settings({override}) {
|
2024-06-18 11:50:51 +02:00
|
|
|
const $subsection_stub = $.create("org-subsection-stub");
|
|
|
|
$subsection_stub.set_find_results(
|
|
|
|
".save-button-controls",
|
|
|
|
$.create("save-button-controls-stub").addClass("hide"),
|
|
|
|
);
|
|
|
|
|
2021-05-24 09:12:53 +02:00
|
|
|
function test_common_policy(property_name) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $property_elem = $(`#id_realm_${CSS.escape(property_name)}`);
|
|
|
|
$property_elem.length = 1;
|
|
|
|
$property_elem.attr("id", `id_realm_${CSS.escape(property_name)}`);
|
2024-06-18 11:50:51 +02:00
|
|
|
$property_elem.closest = () => $subsection_stub;
|
2024-10-03 07:13:43 +02:00
|
|
|
$property_elem[0] = `#id_realm_${CSS.escape(property_name)}`;
|
2021-05-24 09:12:53 +02:00
|
|
|
|
|
|
|
/* Each policy is initialized to 'by_members' and then all the values are tested
|
|
|
|
in the following order - by_admins_only, by_moderators_only, by_full_members,
|
|
|
|
by_members. */
|
|
|
|
|
2024-10-10 00:50:57 +02:00
|
|
|
override(
|
|
|
|
realm,
|
|
|
|
`realm_${property_name}`,
|
|
|
|
settings_config.common_policy_values.by_members.code,
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
$property_elem.val(settings_config.common_policy_values.by_members.code);
|
2021-05-24 09:12:53 +02:00
|
|
|
|
2023-03-02 01:58:25 +01:00
|
|
|
for (const policy_value of Object.values(settings_config.common_policy_values)) {
|
2024-10-10 00:50:57 +02:00
|
|
|
override(realm, `realm_${property_name}`, policy_value.code);
|
2021-05-24 09:12:53 +02:00
|
|
|
settings_org.sync_realm_settings(property_name);
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($property_elem.val(), policy_value.code);
|
2021-05-24 09:12:53 +02:00
|
|
|
}
|
2019-05-07 19:06:05 +02:00
|
|
|
}
|
|
|
|
|
2021-05-24 09:12:53 +02:00
|
|
|
test_common_policy("invite_to_stream_policy");
|
2021-05-23 21:40:20 +02:00
|
|
|
test_common_policy("invite_to_realm_policy");
|
2021-04-21 21:43:27 +02:00
|
|
|
|
2018-06-16 17:25:27 +02:00
|
|
|
{
|
|
|
|
/* Test message content edit limit minutes sync */
|
2022-01-25 11:36:19 +01:00
|
|
|
const $property_elem = $("#id_realm_message_content_edit_limit_minutes");
|
2022-09-02 13:07:11 +02:00
|
|
|
const $property_dropdown_elem = $("#id_realm_message_content_edit_limit_seconds");
|
2022-01-25 11:36:19 +01:00
|
|
|
$property_elem.length = 1;
|
2022-09-02 13:07:11 +02:00
|
|
|
$property_dropdown_elem.length = 1;
|
2022-01-25 11:36:19 +01:00
|
|
|
$property_elem.attr("id", "id_realm_message_content_edit_limit_minutes");
|
2022-09-02 13:07:11 +02:00
|
|
|
$property_dropdown_elem.attr("id", "id_realm_message_content_edit_limit_seconds");
|
2024-06-18 11:50:51 +02:00
|
|
|
$property_dropdown_elem.closest = () => $subsection_stub;
|
2024-10-03 07:13:43 +02:00
|
|
|
$property_dropdown_elem[0] = "#id_realm_message_content_edit_limit_seconds";
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_message_content_edit_limit_seconds", 120);
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
2020-02-12 11:49:02 +01:00
|
|
|
assert.equal($("#id_realm_message_content_edit_limit_minutes").val(), "2");
|
2018-06-16 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Test message content edit limit dropdown value sync */
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_message_content_edit_limit_seconds", 120);
|
2022-04-12 09:56:58 +02:00
|
|
|
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
2022-09-01 14:19:14 +02:00
|
|
|
assert.equal($("#id_realm_message_content_edit_limit_seconds").val(), "120");
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_message_content_edit_limit_seconds", 130);
|
2022-04-12 09:56:58 +02:00
|
|
|
settings_org.sync_realm_settings("message_content_edit_limit_seconds");
|
2022-08-19 16:14:15 +02:00
|
|
|
assert.equal($("#id_realm_message_content_edit_limit_seconds").val(), "custom_period");
|
2018-06-16 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* Test organization joining restrictions settings sync */
|
2022-01-25 11:36:19 +01:00
|
|
|
const $property_elem = $("#id_realm_org_join_restrictions");
|
|
|
|
$property_elem.length = 1;
|
|
|
|
$property_elem.attr("id", "id_realm_org_join_restrictions");
|
2024-06-18 11:50:51 +02:00
|
|
|
$property_elem.closest = () => $subsection_stub;
|
2024-10-03 07:13:43 +02:00
|
|
|
$property_elem[0] = "#id_realm_org_join_restrictions";
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_emails_restricted_to_domains", true);
|
|
|
|
override(realm, "realm_disallow_disposable_email_addresses", false);
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_org_join_restrictions").val(), "only_selected_domain");
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_emails_restricted_to_domains", false);
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_disallow_disposable_email_addresses", true);
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_org_join_restrictions").val(), "no_disposable_email");
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_disallow_disposable_email_addresses", false);
|
2020-07-15 01:29:15 +02:00
|
|
|
settings_org.sync_realm_settings("emails_restricted_to_domains");
|
2018-06-16 17:25:27 +02:00
|
|
|
assert.equal($("#id_realm_org_join_restrictions").val(), "no_restriction");
|
|
|
|
}
|
2024-06-18 11:50:51 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
// Test hiding save-discard buttons on live-updating.
|
|
|
|
const $property_elem = $("#id_realm_invite_to_realm_policy");
|
|
|
|
$property_elem.length = 1;
|
|
|
|
$property_elem.attr("id", "id_realm_invite_to_realm_policy");
|
|
|
|
$property_elem.closest = () => $subsection_stub;
|
|
|
|
|
|
|
|
const save_button_stubs = createSaveButtons("subsection-stub");
|
|
|
|
$subsection_stub.set_find_results(
|
|
|
|
".save-button-controls",
|
|
|
|
save_button_stubs.$save_button_controls,
|
|
|
|
);
|
|
|
|
$property_elem.val(settings_config.common_policy_values.by_admins_only.code);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(
|
|
|
|
realm,
|
|
|
|
"realm_invite_to_realm_policy",
|
|
|
|
settings_config.common_policy_values.by_members.code,
|
|
|
|
);
|
2024-06-18 11:50:51 +02:00
|
|
|
save_button_stubs.$save_button_controls.removeClass("hide");
|
|
|
|
$subsection_stub.set_find_results(".prop-element", [$property_elem]);
|
|
|
|
|
|
|
|
settings_org.sync_realm_settings("invite_to_realm_policy");
|
|
|
|
assert.equal(save_button_stubs.props.hidden, true);
|
|
|
|
}
|
2018-04-16 18:58:27 +02:00
|
|
|
}
|
|
|
|
|
2024-10-10 00:50:57 +02:00
|
|
|
function test_parse_time_limit({override}) {
|
2022-01-25 11:36:19 +01:00
|
|
|
const $elem = $("#id_realm_message_content_edit_limit_minutes");
|
2018-04-28 15:35:14 +02:00
|
|
|
const test_function = (value, expected_value = value) => {
|
2022-01-25 11:36:19 +01:00
|
|
|
$elem.val(value);
|
2024-10-10 00:50:57 +02:00
|
|
|
override(
|
|
|
|
realm,
|
|
|
|
"realm_message_content_edit_limit_seconds",
|
|
|
|
settings_components.parse_time_limit($elem),
|
|
|
|
);
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
2023-10-09 23:29:16 +02:00
|
|
|
settings_components.get_realm_time_limits_in_minutes(
|
2020-07-15 00:34:28 +02:00
|
|
|
"realm_message_content_edit_limit_seconds",
|
|
|
|
),
|
2020-07-28 17:00:59 +02:00
|
|
|
expected_value,
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2018-04-28 15:35:14 +02:00
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
test_function("0.01", "0");
|
|
|
|
test_function("0.1");
|
|
|
|
test_function("0.122", "0.1");
|
|
|
|
test_function("0.155", "0.2");
|
|
|
|
test_function("0.150", "0.1");
|
|
|
|
test_function("0.5");
|
|
|
|
test_function("1");
|
|
|
|
test_function("1.1");
|
|
|
|
test_function("10.5");
|
|
|
|
test_function("50.3");
|
|
|
|
test_function("100");
|
|
|
|
test_function("100.1");
|
|
|
|
test_function("127.79", "127.8");
|
|
|
|
test_function("201.1");
|
|
|
|
test_function("501.15", "501.1");
|
|
|
|
test_function("501.34", "501.3");
|
2018-04-28 15:35:14 +02:00
|
|
|
}
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
function test_discard_changes_button({override}, discard_changes) {
|
2018-06-16 17:25:27 +02:00
|
|
|
const ev = {
|
|
|
|
preventDefault: noop,
|
|
|
|
stopPropagation: noop,
|
|
|
|
};
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_allow_edit_history", true);
|
|
|
|
override(realm, "realm_allow_message_editing", true);
|
|
|
|
override(realm, "realm_message_content_edit_limit_seconds", 3600);
|
|
|
|
override(realm, "realm_message_content_delete_limit_seconds", 120);
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
const $allow_edit_history = $("#id_realm_allow_edit_history").prop("checked", false);
|
2022-08-19 16:14:15 +02:00
|
|
|
const $msg_edit_limit_setting = $("#id_realm_message_content_edit_limit_seconds").val(
|
|
|
|
"custom_period",
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $message_content_edit_limit_minutes = $(
|
2020-07-15 00:34:28 +02:00
|
|
|
"#id_realm_message_content_edit_limit_minutes",
|
|
|
|
).val(130);
|
2022-08-19 16:47:26 +02:00
|
|
|
const $msg_delete_limit_setting = $("#id_realm_message_content_delete_limit_seconds").val(
|
|
|
|
"custom_period",
|
|
|
|
);
|
2022-01-25 11:36:19 +01:00
|
|
|
const $message_content_delete_limit_minutes = $(
|
2020-07-15 00:34:28 +02:00
|
|
|
"#id_realm_message_content_delete_limit_minutes",
|
|
|
|
).val(130);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
$allow_edit_history.attr("id", "id_realm_allow_edit_history");
|
2022-08-19 16:14:15 +02:00
|
|
|
$msg_edit_limit_setting.attr("id", "id_realm_message_content_edit_limit_seconds");
|
2022-08-19 16:47:26 +02:00
|
|
|
$msg_delete_limit_setting.attr("id", "id_realm_message_content_delete_limit_seconds");
|
2022-01-25 11:36:19 +01:00
|
|
|
$message_content_edit_limit_minutes.attr("id", "id_realm_message_content_edit_limit_minutes");
|
|
|
|
$message_content_delete_limit_minutes.attr(
|
2020-07-15 00:34:28 +02:00
|
|
|
"id",
|
|
|
|
"id_realm_message_content_delete_limit_minutes",
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
|
2022-11-03 13:18:42 +01:00
|
|
|
const $discard_button_parent = $(".settings-subsection-parent");
|
2024-06-28 13:23:35 +02:00
|
|
|
$discard_button_parent.set_find_results(".prop-element", [
|
2022-01-25 11:36:19 +01:00
|
|
|
$allow_edit_history,
|
|
|
|
$msg_edit_limit_setting,
|
|
|
|
$msg_delete_limit_setting,
|
2024-06-28 13:23:35 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
const {$discard_button, $save_button_controls, props} = createSaveButtons("msg-editing");
|
|
|
|
$discard_button.closest = (selector) => {
|
|
|
|
assert.equal(selector, ".settings-subsection-parent");
|
|
|
|
return $discard_button_parent;
|
|
|
|
};
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2024-06-28 13:23:35 +02:00
|
|
|
$discard_button_parent.set_find_results(".save-button-controls", $save_button_controls);
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2024-10-07 08:08:20 +02:00
|
|
|
discard_changes.call({to_$: () => $(".save-discard-widget-button.discard-button")}, ev);
|
2018-06-16 17:25:27 +02:00
|
|
|
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($allow_edit_history.prop("checked"), true);
|
2022-09-01 14:19:14 +02:00
|
|
|
assert.equal($msg_edit_limit_setting.val(), "3600");
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($message_content_edit_limit_minutes.val(), "60");
|
2022-09-01 14:19:14 +02:00
|
|
|
assert.equal($msg_delete_limit_setting.val(), "120");
|
2022-01-25 11:36:19 +01:00
|
|
|
assert.equal($message_content_delete_limit_minutes.val(), "2");
|
2022-07-10 01:06:33 +02:00
|
|
|
assert.ok(props.hidden);
|
2018-06-16 17:25:27 +02:00
|
|
|
}
|
|
|
|
|
2021-07-20 14:51:48 +02:00
|
|
|
test("set_up", ({override, override_rewire}) => {
|
2024-10-10 00:50:57 +02:00
|
|
|
override(realm, "realm_available_video_chat_providers", {
|
2019-05-09 09:54:38 +02:00
|
|
|
jitsi_meet: {
|
|
|
|
id: 1,
|
|
|
|
name: "Jitsi Meet",
|
|
|
|
},
|
|
|
|
zoom: {
|
|
|
|
id: 3,
|
|
|
|
name: "Zoom",
|
|
|
|
},
|
2020-04-27 22:41:31 +02:00
|
|
|
big_blue_button: {
|
|
|
|
id: 4,
|
2021-07-06 00:23:51 +02:00
|
|
|
name: "BigBlueButton",
|
2020-04-27 22:41:31 +02:00
|
|
|
},
|
2024-10-10 00:50:57 +02:00
|
|
|
});
|
2024-10-03 07:13:43 +02:00
|
|
|
override(realm, "realm_message_retention_days", null);
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2020-06-11 01:04:12 +02:00
|
|
|
let upload_realm_logo_or_icon;
|
2021-02-23 14:37:26 +01:00
|
|
|
realm_icon.build_realm_icon_widget = (f) => {
|
2020-06-11 01:04:12 +02:00
|
|
|
upload_realm_logo_or_icon = f;
|
2017-06-16 14:41:10 +02:00
|
|
|
};
|
|
|
|
|
2024-06-11 14:02:35 +02:00
|
|
|
override_rewire(settings_org, "init_dropdown_widgets", noop);
|
2024-10-27 11:31:15 +01:00
|
|
|
override_rewire(settings_org, "initialize_group_setting_widgets", noop);
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#id_realm_message_content_edit_limit_minutes").set_parent(
|
2022-09-08 12:19:16 +02:00
|
|
|
$.create("<stub edit limit custom input parent>"),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2022-12-22 19:14:23 +01:00
|
|
|
$("#id_realm_move_messages_within_stream_limit_minutes").set_parent(
|
|
|
|
$.create("<stub move within stream custom input parent>"),
|
|
|
|
);
|
2023-01-30 12:15:36 +01:00
|
|
|
$("#id_realm_move_messages_between_streams_limit_minutes").set_parent(
|
|
|
|
$.create("<stub move between streams custom input parent>"),
|
|
|
|
);
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#id_realm_message_content_delete_limit_minutes").set_parent(
|
2022-09-08 12:19:16 +02:00
|
|
|
$.create("<stub delete limit custom input parent>"),
|
2020-07-15 00:34:28 +02:00
|
|
|
);
|
2022-09-08 12:19:16 +02:00
|
|
|
const $stub_message_content_edit_limit_parent = $.create(
|
|
|
|
"<stub message_content_edit_limit parent",
|
|
|
|
);
|
|
|
|
$("#id_realm_message_content_edit_limit_seconds").set_parent(
|
|
|
|
$stub_message_content_edit_limit_parent,
|
|
|
|
);
|
|
|
|
|
2022-12-22 19:14:23 +01:00
|
|
|
const $stub_move_within_stream_limit_parent = $.create("<stub move_within_stream_limit parent");
|
|
|
|
$("#id_realm_move_messages_within_stream_limit_seconds").set_parent(
|
|
|
|
$stub_move_within_stream_limit_parent,
|
|
|
|
);
|
|
|
|
|
2023-01-30 12:15:36 +01:00
|
|
|
const $stub_move_between_streams_limit_parent = $.create(
|
|
|
|
"<stub move_between_streams_limit parent",
|
|
|
|
);
|
|
|
|
$("#id_realm_move_messages_between_streams_limit_seconds").set_parent(
|
|
|
|
$stub_move_between_streams_limit_parent,
|
|
|
|
);
|
|
|
|
|
2022-09-08 12:19:16 +02:00
|
|
|
const $stub_message_content_delete_limit_parent = $.create(
|
|
|
|
"<stub message_content_delete_limit parent",
|
|
|
|
);
|
|
|
|
$("#id_realm_message_content_delete_limit_seconds").set_parent(
|
|
|
|
$stub_message_content_delete_limit_parent,
|
|
|
|
);
|
|
|
|
|
|
|
|
const $custom_edit_limit_input = $("#id_realm_message_content_edit_limit_minutes");
|
|
|
|
$stub_message_content_edit_limit_parent.set_find_results(
|
2023-01-16 10:46:45 +01:00
|
|
|
".time-limit-custom-input",
|
2022-09-08 12:19:16 +02:00
|
|
|
$custom_edit_limit_input,
|
|
|
|
);
|
|
|
|
$custom_edit_limit_input.attr("id", "id_realm_message_content_edit_limit_minutes");
|
|
|
|
|
2022-12-22 19:14:23 +01:00
|
|
|
const $custom_move_within_stream_limit_input = $(
|
|
|
|
"#id_realm_move_messages_within_stream_limit_minutes",
|
|
|
|
);
|
|
|
|
$stub_move_within_stream_limit_parent.set_find_results(
|
|
|
|
".time-limit-custom-input",
|
|
|
|
$custom_move_within_stream_limit_input,
|
|
|
|
);
|
|
|
|
$custom_move_within_stream_limit_input.attr(
|
|
|
|
"id",
|
|
|
|
"id_realm_move_messages_within_stream_limit_minutes",
|
|
|
|
);
|
|
|
|
|
2023-01-30 12:15:36 +01:00
|
|
|
const $custom_move_between_streams_limit_input = $(
|
|
|
|
"#id_realm_move_messages_between_streams_limit_minutes",
|
|
|
|
);
|
|
|
|
$stub_move_between_streams_limit_parent.set_find_results(
|
|
|
|
".time-limit-custom-input",
|
|
|
|
$custom_move_between_streams_limit_input,
|
|
|
|
);
|
|
|
|
$custom_move_between_streams_limit_input.attr(
|
|
|
|
"id",
|
|
|
|
"id_realm_move_messages_between_streams_limit_minutes",
|
|
|
|
);
|
|
|
|
|
2022-09-08 12:19:16 +02:00
|
|
|
const $custom_delete_limit_input = $("#id_realm_message_content_delete_limit_minutes");
|
|
|
|
$stub_message_content_delete_limit_parent.set_find_results(
|
2023-01-16 10:46:45 +01:00
|
|
|
".time-limit-custom-input",
|
2022-09-08 12:19:16 +02:00
|
|
|
$custom_delete_limit_input,
|
|
|
|
);
|
|
|
|
$custom_delete_limit_input.attr("id", "id_realm_message_content_delete_limit_minutes");
|
|
|
|
|
2022-11-04 11:11:33 +01:00
|
|
|
const $stub_realm_message_retention_parent = $.create(
|
|
|
|
"<stub message retention setting parent>",
|
2022-11-04 11:11:33 +01:00
|
|
|
);
|
2022-11-04 11:11:33 +01:00
|
|
|
const $realm_message_retention_custom_input = $("#id_realm_message_retention_custom_input");
|
|
|
|
$("#id_realm_message_retention_days").set_parent($stub_realm_message_retention_parent);
|
|
|
|
$realm_message_retention_custom_input.set_parent($stub_realm_message_retention_parent);
|
|
|
|
$stub_realm_message_retention_parent.set_find_results(
|
|
|
|
".message-retention-setting-custom-input",
|
|
|
|
$realm_message_retention_custom_input,
|
|
|
|
);
|
|
|
|
$realm_message_retention_custom_input.attr("id", "id_realm_message_retention_custom_input");
|
|
|
|
|
2022-12-12 18:21:08 +01:00
|
|
|
const $stub_realm_waiting_period_threshold_parent = $.create(
|
|
|
|
"<stub waiting period threshold setting parent>",
|
|
|
|
);
|
|
|
|
const $realm_waiting_period_threshold_custom_input = $(
|
|
|
|
"#id_realm_waiting_period_threshold_custom_input",
|
|
|
|
);
|
|
|
|
$("#id_realm_waiting_period_threshold").set_parent($stub_realm_waiting_period_threshold_parent);
|
|
|
|
$realm_waiting_period_threshold_custom_input.set_parent(
|
|
|
|
$stub_realm_waiting_period_threshold_parent,
|
|
|
|
);
|
|
|
|
$stub_realm_waiting_period_threshold_parent.set_find_results(
|
2023-01-16 10:46:45 +01:00
|
|
|
".time-limit-custom-input",
|
2022-12-12 18:21:08 +01:00
|
|
|
$realm_waiting_period_threshold_custom_input,
|
|
|
|
);
|
|
|
|
$realm_waiting_period_threshold_custom_input.attr(
|
|
|
|
"id",
|
|
|
|
"id_realm_waiting_period_threshold_custom_input",
|
|
|
|
);
|
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("#message_content_in_email_notifications_label").set_parent(
|
|
|
|
$.create("<stub in-content setting checkbox>"),
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#enable_digest_emails_label").set_parent($.create("<stub digest setting checkbox>"));
|
|
|
|
$("#id_realm_digest_weekday").set_parent($.create("<stub digest weekday setting dropdown>"));
|
|
|
|
$("#allowed_domains_label").set_parent($.create("<stub-allowed-domain-label-parent>"));
|
2022-01-25 11:36:19 +01:00
|
|
|
const $waiting_period_parent_elem = $.create("waiting-period-parent-stub");
|
|
|
|
$("#id_realm_waiting_period_threshold").set_parent($waiting_period_parent_elem);
|
2024-07-26 05:42:14 +02:00
|
|
|
$("#id_realm_can_create_web_public_channel_group").set_parent(
|
|
|
|
$.create("<stub-can-create-web-public-channel-group-parent>"),
|
2021-11-19 10:29:39 +01:00
|
|
|
);
|
2018-08-18 12:31:21 +02:00
|
|
|
|
2024-02-07 10:40:47 +01:00
|
|
|
override_rewire(settings_components, "get_input_element_value", (elem) => {
|
|
|
|
if ($(elem).data() === "number") {
|
|
|
|
return Number.parseInt($(elem).val(), 10);
|
|
|
|
}
|
|
|
|
return $(elem).val();
|
|
|
|
});
|
|
|
|
|
2017-06-16 14:41:10 +02:00
|
|
|
// TEST set_up() here, but this mostly just allows us to
|
|
|
|
// get access to the click handlers.
|
2024-02-13 02:08:16 +01:00
|
|
|
override(current_user, "is_owner", true);
|
2017-06-16 14:41:10 +02:00
|
|
|
settings_org.set_up();
|
|
|
|
|
2020-07-21 00:23:06 +02:00
|
|
|
test_submit_settings_form(
|
2021-03-14 14:08:11 +01:00
|
|
|
override,
|
2021-09-29 11:46:12 +02:00
|
|
|
$(".admin-realm-form").get_on_handler(
|
2020-07-21 00:23:06 +02:00
|
|
|
"click",
|
2021-06-03 18:15:17 +02:00
|
|
|
".subsection-header .subsection-changes-save button",
|
2020-07-21 00:23:06 +02:00
|
|
|
),
|
|
|
|
);
|
2021-03-14 14:08:11 +01:00
|
|
|
test_upload_realm_icon(override, upload_realm_logo_or_icon);
|
2018-03-14 23:50:17 +01:00
|
|
|
test_extract_property_name();
|
2018-03-29 02:02:01 +02:00
|
|
|
test_change_save_button_state();
|
2024-10-09 22:20:06 +02:00
|
|
|
test_sync_realm_settings({override});
|
2024-10-10 00:50:57 +02:00
|
|
|
test_parse_time_limit({override});
|
2020-07-21 00:23:06 +02:00
|
|
|
test_discard_changes_button(
|
2024-10-09 22:20:06 +02:00
|
|
|
{override},
|
2021-09-29 11:46:12 +02:00
|
|
|
$(".admin-realm-form").get_on_handler(
|
2020-07-21 00:23:06 +02:00
|
|
|
"click",
|
2021-06-03 18:15:17 +02:00
|
|
|
".subsection-header .subsection-changes-discard button",
|
2020-07-21 00:23:06 +02:00
|
|
|
),
|
|
|
|
);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2021-03-14 14:08:11 +01:00
|
|
|
test("test get_organization_settings_options", () => {
|
2020-01-23 07:01:34 +01:00
|
|
|
const sorted_option_values = settings_org.get_organization_settings_options();
|
2021-04-28 20:39:24 +02:00
|
|
|
const sorted_common_policy_values = sorted_option_values.common_policy_values;
|
|
|
|
const expected_common_policy_values = [
|
2020-01-23 07:01:34 +01:00
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_admins_only",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 1,
|
|
|
|
code: 2,
|
2021-04-13 06:51:54 +02:00
|
|
|
description: $t({defaultMessage: "Admins"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
{
|
2021-04-21 21:43:27 +02:00
|
|
|
key: "by_moderators_only",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 2,
|
2021-04-21 21:43:27 +02:00
|
|
|
code: 4,
|
|
|
|
description: $t({defaultMessage: "Admins and moderators"}),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "by_full_members",
|
|
|
|
order: 3,
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 3,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and full members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_members",
|
2021-04-21 21:43:27 +02:00
|
|
|
order: 4,
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 1,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
];
|
2021-04-28 20:39:24 +02:00
|
|
|
assert.deepEqual(sorted_common_policy_values, expected_common_policy_values);
|
2020-01-23 07:01:34 +01:00
|
|
|
});
|
|
|
|
|
2021-03-14 14:08:11 +01:00
|
|
|
test("test get_sorted_options_list", () => {
|
2020-01-23 07:01:34 +01:00
|
|
|
const option_values_1 = {
|
|
|
|
by_admins_only: {
|
|
|
|
order: 3,
|
|
|
|
code: 2,
|
2021-04-13 06:51:54 +02:00
|
|
|
description: $t({defaultMessage: "Admins"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
by_members: {
|
|
|
|
order: 2,
|
|
|
|
code: 1,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
by_full_members: {
|
|
|
|
order: 1,
|
|
|
|
code: 3,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and full members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
let expected_option_values = [
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_full_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 1,
|
|
|
|
code: 3,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and full members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 2,
|
|
|
|
code: 1,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_admins_only",
|
2020-01-23 07:01:34 +01:00
|
|
|
order: 3,
|
|
|
|
code: 2,
|
2021-04-13 06:51:54 +02:00
|
|
|
description: $t({defaultMessage: "Admins"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
];
|
2023-10-09 23:29:16 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
settings_components.get_sorted_options_list(option_values_1),
|
|
|
|
expected_option_values,
|
|
|
|
);
|
2020-01-23 07:01:34 +01:00
|
|
|
|
|
|
|
const option_values_2 = {
|
|
|
|
by_admins_only: {
|
|
|
|
code: 1,
|
2021-04-13 06:51:54 +02:00
|
|
|
description: $t({defaultMessage: "Admins"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
by_members: {
|
|
|
|
code: 2,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
by_full_members: {
|
|
|
|
code: 3,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and full members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
expected_option_values = [
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_admins_only",
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 1,
|
2021-04-13 06:51:54 +02:00
|
|
|
description: $t({defaultMessage: "Admins"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_full_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 3,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and full members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
{
|
2020-07-15 01:29:15 +02:00
|
|
|
key: "by_members",
|
2020-01-23 07:01:34 +01:00
|
|
|
code: 2,
|
2021-08-23 14:58:02 +02:00
|
|
|
description: $t({defaultMessage: "Admins, moderators and members"}),
|
2020-01-23 07:01:34 +01:00
|
|
|
},
|
|
|
|
];
|
2023-10-09 23:29:16 +02:00
|
|
|
assert.deepEqual(
|
|
|
|
settings_components.get_sorted_options_list(option_values_2),
|
|
|
|
expected_option_values,
|
|
|
|
);
|
2020-01-23 07:01:34 +01:00
|
|
|
});
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
test("misc", ({override}) => {
|
|
|
|
override(current_user, "is_admin", false);
|
2023-01-14 21:31:46 +01:00
|
|
|
$("#user-avatar-upload-widget").length = 1;
|
|
|
|
$("#user_details_section").length = 1;
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_name_changes_disabled", false);
|
|
|
|
override(realm, "server_name_changes_disabled", false);
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("#full_name").prop("disabled"));
|
2023-01-25 18:50:46 +01:00
|
|
|
assert.ok(!$("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_name_changes_disabled", true);
|
|
|
|
override(realm, "server_name_changes_disabled", false);
|
2019-05-03 08:09:03 +02:00
|
|
|
settings_account.update_name_change_display();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($("#full_name").prop("disabled"));
|
2023-01-25 18:50:46 +01:00
|
|
|
assert.ok($("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
2019-05-03 08:09:03 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_name_changes_disabled", true);
|
|
|
|
override(realm, "server_name_changes_disabled", true);
|
2019-05-03 08:09:03 +02:00
|
|
|
settings_account.update_name_change_display();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($("#full_name").prop("disabled"));
|
2023-01-25 18:50:46 +01:00
|
|
|
assert.ok($("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
2019-05-03 08:09:03 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_name_changes_disabled", false);
|
|
|
|
override(realm, "server_name_changes_disabled", true);
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok($("#full_name").prop("disabled"));
|
2023-01-25 18:50:46 +01:00
|
|
|
assert.ok($("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_email_changes_disabled", false);
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2022-12-14 13:45:08 +01:00
|
|
|
assert.ok(!$("#change_email_button").prop("disabled"));
|
2018-01-04 13:02:17 +01:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_email_changes_disabled", true);
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2022-12-14 13:45:08 +01:00
|
|
|
assert.ok($("#change_email_button").prop("disabled"));
|
2017-06-16 14:41:10 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_avatar_changes_disabled", false);
|
|
|
|
override(realm, "server_avatar_changes_disabled", false);
|
2019-04-23 04:51:04 +02:00
|
|
|
settings_account.update_avatar_change_display();
|
2023-01-03 17:21:08 +01:00
|
|
|
assert.ok(!$("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_avatar_changes_disabled", true);
|
|
|
|
override(realm, "server_avatar_changes_disabled", false);
|
2019-04-29 08:41:00 +02:00
|
|
|
settings_account.update_avatar_change_display();
|
2023-01-03 17:21:08 +01:00
|
|
|
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_avatar_changes_disabled", false);
|
|
|
|
override(realm, "server_avatar_changes_disabled", true);
|
2019-04-29 08:41:00 +02:00
|
|
|
settings_account.update_avatar_change_display();
|
2023-01-03 17:21:08 +01:00
|
|
|
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_avatar_changes_disabled", true);
|
|
|
|
override(realm, "server_avatar_changes_disabled", true);
|
2019-04-23 04:51:04 +02:00
|
|
|
settings_account.update_avatar_change_display();
|
2023-01-03 17:21:08 +01:00
|
|
|
assert.ok($("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
2019-04-23 04:51:04 +02:00
|
|
|
|
2018-03-02 21:44:14 +01:00
|
|
|
// If organization admin, these UI elements are never disabled.
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", true);
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_name_change_display();
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!$("#full_name").prop("disabled"));
|
2023-01-25 18:50:46 +01:00
|
|
|
assert.ok(!$("#full_name_input_container").hasClass("disabled_setting_tooltip"));
|
2018-02-02 16:54:26 +01:00
|
|
|
|
2018-03-02 21:44:14 +01:00
|
|
|
settings_account.update_email_change_display();
|
2022-12-14 13:45:08 +01:00
|
|
|
assert.ok(!$("#change_email_button").prop("disabled"));
|
2018-02-02 16:54:26 +01:00
|
|
|
|
2023-01-03 17:21:08 +01:00
|
|
|
settings_account.update_avatar_change_display();
|
|
|
|
assert.ok(!$("#user-avatar-upload-widget .image_upload_button").hasClass("hide"));
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|