2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2020-11-30 23:46:45 +01:00
|
|
|
const {strict: assert} = require("assert");
|
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const {zrequire} = require("./lib/namespace");
|
|
|
|
const {run_test} = require("./lib/test");
|
2024-02-13 02:08:24 +01:00
|
|
|
const {current_user, page_params, realm, user_settings} = require("./lib/zpage_params");
|
2020-12-01 23:21:38 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
const settings_data = zrequire("settings_data");
|
|
|
|
const settings_config = zrequire("settings_config");
|
2023-08-03 16:06:40 +02:00
|
|
|
const user_groups = zrequire("user_groups");
|
2020-02-25 12:46:14 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Some methods in settings_data are fairly
|
|
|
|
trivial, so the meaningful tests happen
|
|
|
|
at the higher layers, such as when we
|
|
|
|
test people.js.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const isaac = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "isaac@example.com",
|
|
|
|
delivery_email: "isaac-delivery@example.com",
|
2021-04-28 20:54:03 +02:00
|
|
|
user_id: 30,
|
|
|
|
full_name: "Isaac",
|
2020-02-25 12:46:14 +01:00
|
|
|
};
|
|
|
|
|
2022-12-09 17:34:00 +01:00
|
|
|
run_test("user_can_change_email", () => {
|
|
|
|
const can_change_email = settings_data.user_can_change_email;
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
2022-12-09 17:34:00 +01:00
|
|
|
assert.equal(can_change_email(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_email_changes_disabled = true;
|
2022-12-09 17:34:00 +01:00
|
|
|
assert.equal(can_change_email(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_email_changes_disabled = false;
|
2022-12-09 17:34:00 +01:00
|
|
|
assert.equal(can_change_email(), true);
|
|
|
|
});
|
|
|
|
|
2021-03-21 16:46:13 +01:00
|
|
|
run_test("user_can_change_name", () => {
|
|
|
|
const can_change_name = settings_data.user_can_change_name;
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_name_changes_disabled = true;
|
|
|
|
realm.server_name_changes_disabled = false;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_name_changes_disabled = false;
|
|
|
|
realm.server_name_changes_disabled = false;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), true);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_name_changes_disabled = false;
|
|
|
|
realm.server_name_changes_disabled = true;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), false);
|
|
|
|
});
|
|
|
|
|
|
|
|
run_test("user_can_change_avatar", () => {
|
|
|
|
const can_change_avatar = settings_data.user_can_change_avatar;
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_avatar_changes_disabled = true;
|
|
|
|
realm.server_avatar_changes_disabled = false;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_avatar_changes_disabled = false;
|
|
|
|
realm.server_avatar_changes_disabled = false;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), true);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_avatar_changes_disabled = false;
|
|
|
|
realm.server_avatar_changes_disabled = true;
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), false);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("user_can_change_logo", () => {
|
2020-06-17 07:43:53 +02:00
|
|
|
const can_change_logo = settings_data.user_can_change_logo;
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.zulip_plan_is_not_limited = true;
|
2020-06-17 07:43:53 +02:00
|
|
|
assert.equal(can_change_logo(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.zulip_plan_is_not_limited = false;
|
2020-06-17 07:43:53 +02:00
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.zulip_plan_is_not_limited = false;
|
2020-06-17 07:43:53 +02:00
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.zulip_plan_is_not_limited = true;
|
2020-06-17 07:43:53 +02:00
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
});
|
2021-04-28 20:54:03 +02:00
|
|
|
|
2021-04-30 09:24:29 +02:00
|
|
|
function test_policy(label, policy, validation_func) {
|
|
|
|
run_test(label, () => {
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_policy_values.by_admins_only.code;
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_moderator = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_policy_values.by_moderators_only.code;
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_moderator = false;
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_guest = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_policy_values.by_members.code;
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_guest = false;
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
|
2021-07-22 08:00:06 +02:00
|
|
|
page_params.is_spectator = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_policy_values.by_members.code;
|
2021-07-22 08:00:06 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
|
|
|
page_params.is_spectator = false;
|
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_policy_values.by_full_members.code;
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.user_id = 30;
|
2021-04-30 09:24:29 +02:00
|
|
|
isaac.date_joined = new Date(Date.now());
|
2021-07-19 19:26:17 +02:00
|
|
|
settings_data.initialize(isaac.date_joined);
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_waiting_period_threshold = 10;
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
|
|
|
isaac.date_joined = new Date(Date.now() - 20 * 86400000);
|
2021-07-19 19:26:17 +02:00
|
|
|
settings_data.initialize(isaac.date_joined);
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test_policy(
|
|
|
|
"user_can_subscribe_other_users",
|
|
|
|
"realm_invite_to_stream_policy",
|
|
|
|
settings_data.user_can_subscribe_other_users,
|
|
|
|
);
|
|
|
|
test_policy(
|
|
|
|
"user_can_invite_others_to_realm",
|
|
|
|
"realm_invite_to_realm_policy",
|
2023-06-26 23:38:08 +02:00
|
|
|
settings_data.user_can_invite_users_by_email,
|
2021-04-30 09:24:29 +02:00
|
|
|
);
|
2021-04-30 09:35:20 +02:00
|
|
|
test_policy(
|
|
|
|
"user_can_move_messages_between_streams",
|
|
|
|
"realm_move_messages_between_streams_policy",
|
|
|
|
settings_data.user_can_move_messages_between_streams,
|
|
|
|
);
|
2021-06-03 15:47:03 +02:00
|
|
|
test_policy(
|
|
|
|
"user_can_edit_user_groups",
|
|
|
|
"realm_user_group_edit_policy",
|
|
|
|
settings_data.user_can_edit_user_groups,
|
|
|
|
);
|
2021-05-17 19:32:35 +02:00
|
|
|
test_policy(
|
|
|
|
"user_can_add_custom_emoji",
|
|
|
|
"realm_add_custom_emoji_policy",
|
|
|
|
settings_data.user_can_add_custom_emoji,
|
|
|
|
);
|
2021-05-26 21:20:11 +02:00
|
|
|
|
2021-06-23 15:42:54 +02:00
|
|
|
function test_message_policy(label, policy, validation_func) {
|
|
|
|
run_test(label, () => {
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_message_policy_values.by_admins_only.code;
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), true);
|
2021-05-26 21:20:11 +02:00
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
|
|
|
current_user.is_moderator = true;
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), false);
|
2021-05-26 21:20:11 +02:00
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_message_policy_values.by_moderators_only.code;
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), true);
|
2021-05-26 21:20:11 +02:00
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_moderator = false;
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), false);
|
2021-05-26 21:20:11 +02:00
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_guest = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_message_policy_values.by_everyone.code;
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_message_policy_values.by_members.code;
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_guest = false;
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm[policy] = settings_config.common_message_policy_values.by_full_members.code;
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.user_id = 30;
|
2021-06-23 15:42:54 +02:00
|
|
|
isaac.date_joined = new Date(Date.now());
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_waiting_period_threshold = 10;
|
2021-07-19 19:26:17 +02:00
|
|
|
settings_data.initialize(isaac.date_joined);
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
|
|
|
isaac.date_joined = new Date(Date.now() - 20 * 86400000);
|
2021-07-19 19:26:17 +02:00
|
|
|
settings_data.initialize(isaac.date_joined);
|
2021-06-23 15:42:54 +02:00
|
|
|
assert.equal(validation_func(), true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test_message_policy(
|
2022-10-18 13:48:30 +02:00
|
|
|
"user_can_move_messages_to_another_topic",
|
2021-06-23 15:42:54 +02:00
|
|
|
"realm_edit_topic_policy",
|
2022-10-18 13:48:30 +02:00
|
|
|
settings_data.user_can_move_messages_to_another_topic,
|
2021-06-23 15:42:54 +02:00
|
|
|
);
|
2021-07-08 13:14:17 +02:00
|
|
|
|
2022-10-18 13:48:30 +02:00
|
|
|
run_test("user_can_move_messages_to_another_topic_nobody_case", () => {
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
|
|
|
current_user.is_guest = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_edit_topic_policy = settings_config.edit_topic_policy_values.nobody.code;
|
2022-10-18 13:48:30 +02:00
|
|
|
assert.equal(settings_data.user_can_move_messages_to_another_topic(), false);
|
2022-09-28 16:30:10 +02:00
|
|
|
});
|
|
|
|
|
2022-09-29 09:03:12 +02:00
|
|
|
run_test("user_can_move_messages_between_streams_nobody_case", () => {
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
|
|
|
current_user.is_guest = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_move_messages_between_streams_policy =
|
2022-09-29 09:03:12 +02:00
|
|
|
settings_config.move_messages_between_streams_policy_values.nobody.code;
|
|
|
|
assert.equal(settings_data.user_can_move_messages_between_streams(), false);
|
|
|
|
});
|
|
|
|
|
2021-06-23 12:53:38 +02:00
|
|
|
test_message_policy(
|
|
|
|
"user_can_delete_own_message",
|
|
|
|
"realm_delete_own_message_policy",
|
|
|
|
settings_data.user_can_delete_own_message,
|
|
|
|
);
|
|
|
|
|
2021-07-08 13:14:17 +02:00
|
|
|
run_test("using_dark_theme", () => {
|
2024-06-19 23:30:39 +02:00
|
|
|
user_settings.color_scheme = settings_config.color_scheme_values.dark.code;
|
2021-07-08 13:14:17 +02:00
|
|
|
assert.equal(settings_data.using_dark_theme(), true);
|
|
|
|
|
2021-07-28 16:00:58 +02:00
|
|
|
user_settings.color_scheme = settings_config.color_scheme_values.automatic.code;
|
2021-07-08 13:14:17 +02:00
|
|
|
|
|
|
|
window.matchMedia = (query) => {
|
|
|
|
assert.equal(query, "(prefers-color-scheme: dark)");
|
|
|
|
return {matches: true};
|
|
|
|
};
|
|
|
|
assert.equal(settings_data.using_dark_theme(), true);
|
|
|
|
|
|
|
|
window.matchMedia = (query) => {
|
|
|
|
assert.equal(query, "(prefers-color-scheme: dark)");
|
|
|
|
return {matches: false};
|
|
|
|
};
|
|
|
|
assert.equal(settings_data.using_dark_theme(), false);
|
|
|
|
|
2024-06-19 23:30:39 +02:00
|
|
|
user_settings.color_scheme = settings_config.color_scheme_values.light.code;
|
2021-07-08 13:14:17 +02:00
|
|
|
assert.equal(settings_data.using_dark_theme(), false);
|
|
|
|
});
|
2021-07-18 18:18:28 +02:00
|
|
|
|
|
|
|
run_test("user_can_invite_others_to_realm_nobody_case", () => {
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = true;
|
|
|
|
current_user.is_guest = false;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_invite_to_realm_policy =
|
2023-06-26 23:38:08 +02:00
|
|
|
settings_config.email_invite_to_realm_policy_values.nobody.code;
|
|
|
|
assert.equal(settings_data.user_can_invite_users_by_email(), false);
|
2021-07-18 18:18:28 +02:00
|
|
|
});
|
2021-11-19 17:36:00 +01:00
|
|
|
|
|
|
|
run_test("user_can_create_web_public_streams", () => {
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_owner = true;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.server_web_public_streams_enabled = true;
|
|
|
|
realm.realm_enable_spectator_access = true;
|
|
|
|
realm.realm_create_web_public_stream_policy =
|
2021-11-19 17:36:00 +01:00
|
|
|
settings_config.create_web_public_stream_policy_values.nobody.code;
|
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_create_web_public_stream_policy =
|
2021-11-19 17:36:00 +01:00
|
|
|
settings_config.create_web_public_stream_policy_values.by_owners_only.code;
|
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), true);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_enable_spectator_access = false;
|
|
|
|
realm.server_web_public_streams_enabled = true;
|
2021-11-19 17:36:00 +01:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_enable_spectator_access = true;
|
|
|
|
realm.server_web_public_streams_enabled = false;
|
2021-11-19 17:36:00 +01:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_enable_spectator_access = false;
|
|
|
|
realm.server_web_public_streams_enabled = false;
|
2021-11-19 17:36:00 +01:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_enable_spectator_access = true;
|
|
|
|
realm.server_web_public_streams_enabled = true;
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_owner = false;
|
|
|
|
current_user.is_admin = true;
|
2021-11-19 17:36:00 +01:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_create_web_public_stream_policy =
|
2021-11-19 17:36:00 +01:00
|
|
|
settings_config.create_web_public_stream_policy_values.by_admins_only.code;
|
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_admin = false;
|
|
|
|
current_user.is_moderator = true;
|
2021-11-19 17:36:00 +01:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_create_web_public_stream_policy =
|
2021-11-19 17:36:00 +01:00
|
|
|
settings_config.create_web_public_stream_policy_values.by_moderators_only.code;
|
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_moderator = false;
|
2021-11-19 17:36:00 +01:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
});
|
2023-02-13 19:42:58 +01:00
|
|
|
|
|
|
|
run_test("user_email_not_configured", () => {
|
|
|
|
const user_email_not_configured = settings_data.user_email_not_configured;
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_owner = false;
|
2023-02-13 19:42:58 +01:00
|
|
|
assert.equal(user_email_not_configured(), false);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_owner = true;
|
|
|
|
current_user.delivery_email = "";
|
2023-02-13 19:42:58 +01:00
|
|
|
assert.equal(user_email_not_configured(), true);
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.delivery_email = "name@example.com";
|
2023-02-13 19:42:58 +01:00
|
|
|
assert.equal(user_email_not_configured(), false);
|
|
|
|
});
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-06-19 15:38:07 +02:00
|
|
|
function test_realm_group_settings(label, setting_name, validation_func) {
|
|
|
|
run_test(label, () => {
|
|
|
|
const admin_user_id = 1;
|
|
|
|
const moderator_user_id = 2;
|
|
|
|
const member_user_id = 3;
|
|
|
|
|
|
|
|
const admins = {
|
|
|
|
name: "Admins",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([admin_user_id]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
};
|
|
|
|
const moderators = {
|
|
|
|
name: "Moderators",
|
|
|
|
id: 2,
|
|
|
|
members: new Set([moderator_user_id]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1]),
|
|
|
|
};
|
|
|
|
|
|
|
|
user_groups.initialize({realm_user_groups: [admins, moderators]});
|
|
|
|
page_params.is_spectator = true;
|
|
|
|
assert.equal(validation_func(), false);
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-06-19 15:38:07 +02:00
|
|
|
page_params.is_spectator = false;
|
|
|
|
realm[setting_name] = 1;
|
|
|
|
current_user.user_id = admin_user_id;
|
|
|
|
assert.equal(validation_func(), true);
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-06-19 15:38:07 +02:00
|
|
|
current_user.user_id = moderator_user_id;
|
|
|
|
assert.equal(validation_func(), false);
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-06-19 15:38:07 +02:00
|
|
|
realm[setting_name] = 2;
|
|
|
|
current_user.user_id = moderator_user_id;
|
|
|
|
assert.equal(validation_func(), true);
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-06-19 15:38:07 +02:00
|
|
|
current_user.user_id = member_user_id;
|
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
});
|
|
|
|
}
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-06-19 15:38:07 +02:00
|
|
|
test_realm_group_settings(
|
|
|
|
"user_can_create_multiuse_invite",
|
|
|
|
"realm_create_multiuse_invite_group",
|
|
|
|
settings_data.user_can_create_multiuse_invite,
|
|
|
|
);
|
2023-09-22 19:32:14 +02:00
|
|
|
|
|
|
|
run_test("can_edit_user_group", () => {
|
|
|
|
const students = {
|
|
|
|
description: "Students group",
|
|
|
|
name: "Students",
|
|
|
|
id: 0,
|
|
|
|
members: new Set([1, 2]),
|
|
|
|
is_system_group: false,
|
|
|
|
direct_subgroup_ids: new Set([4, 5]),
|
|
|
|
can_mention_group: 2,
|
|
|
|
};
|
|
|
|
user_groups.initialize({
|
|
|
|
realm_user_groups: [students],
|
|
|
|
});
|
|
|
|
|
2024-06-12 12:04:08 +02:00
|
|
|
page_params.is_spectator = true;
|
2023-09-22 19:32:14 +02:00
|
|
|
assert.ok(!settings_data.can_edit_user_group(students.id));
|
|
|
|
|
2024-06-12 12:04:08 +02:00
|
|
|
page_params.is_spectator = false;
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.user_id = 3;
|
|
|
|
current_user.is_guest = true;
|
2023-09-22 19:32:14 +02:00
|
|
|
assert.ok(!settings_data.can_edit_user_group(students.id));
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_guest = false;
|
|
|
|
current_user.is_moderator = true;
|
2023-09-22 19:32:14 +02:00
|
|
|
assert.ok(settings_data.can_edit_user_group(students.id));
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.is_moderator = false;
|
2023-09-22 19:32:14 +02:00
|
|
|
assert.ok(!settings_data.can_edit_user_group(students.id));
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.user_id = 2;
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_waiting_period_threshold = 0;
|
2023-09-22 19:32:14 +02:00
|
|
|
assert.ok(settings_data.can_edit_user_group(students.id));
|
|
|
|
});
|
2023-09-25 10:15:19 +02:00
|
|
|
|
|
|
|
run_test("type_id_to_string", () => {
|
|
|
|
page_params.bot_types = [
|
|
|
|
{
|
|
|
|
type_id: 1,
|
|
|
|
name: "Generic bot",
|
|
|
|
allowed: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type_id: 2,
|
|
|
|
name: "Incoming webhook",
|
|
|
|
allowed: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2023-09-26 05:52:27 +02:00
|
|
|
assert.equal(settings_data.bot_type_id_to_string(1), "Generic bot");
|
|
|
|
assert.equal(settings_data.bot_type_id_to_string(2), "Incoming webhook");
|
|
|
|
assert.equal(settings_data.bot_type_id_to_string(5), undefined);
|
2023-09-25 10:15:19 +02:00
|
|
|
});
|
2023-11-28 18:24:43 +01:00
|
|
|
|
|
|
|
run_test("user_can_access_all_other_users", () => {
|
|
|
|
const guest_user_id = 1;
|
|
|
|
const member_user_id = 2;
|
|
|
|
|
|
|
|
const members = {
|
|
|
|
name: "role:members",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([member_user_id]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
};
|
|
|
|
const everyone = {
|
|
|
|
name: "role:everyone",
|
|
|
|
id: 2,
|
|
|
|
members: new Set([guest_user_id]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1]),
|
|
|
|
};
|
|
|
|
|
|
|
|
user_groups.initialize({realm_user_groups: [members, everyone]});
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_can_access_all_users_group = members.id;
|
2023-11-28 18:24:43 +01:00
|
|
|
|
|
|
|
// Test spectators case.
|
2024-06-12 12:04:08 +02:00
|
|
|
page_params.is_spectator = true;
|
2023-11-28 18:24:43 +01:00
|
|
|
assert.ok(settings_data.user_can_access_all_other_users());
|
|
|
|
|
2024-06-12 12:04:08 +02:00
|
|
|
page_params.is_spectator = false;
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.user_id = member_user_id;
|
2023-11-28 18:24:43 +01:00
|
|
|
assert.ok(settings_data.user_can_access_all_other_users());
|
|
|
|
|
2024-02-13 02:08:16 +01:00
|
|
|
current_user.user_id = guest_user_id;
|
2023-11-28 18:24:43 +01:00
|
|
|
assert.ok(!settings_data.user_can_access_all_other_users());
|
|
|
|
|
2024-02-13 02:08:24 +01:00
|
|
|
realm.realm_can_access_all_users_group = everyone.id;
|
2023-11-28 18:24:43 +01:00
|
|
|
assert.ok(settings_data.user_can_access_all_other_users());
|
|
|
|
});
|
2024-05-31 09:49:10 +02:00
|
|
|
|
2024-06-19 15:38:07 +02:00
|
|
|
test_realm_group_settings(
|
|
|
|
"user_can_create_public_streams",
|
|
|
|
"realm_can_create_public_channel_group",
|
|
|
|
settings_data.user_can_create_public_streams,
|
|
|
|
);
|
2024-06-17 16:06:49 +02:00
|
|
|
|
|
|
|
test_realm_group_settings(
|
|
|
|
"user_can_create_private_streams",
|
|
|
|
"realm_can_create_private_channel_group",
|
|
|
|
settings_data.user_can_create_private_streams,
|
|
|
|
);
|