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 {mock_esm, with_overrides, zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test} = require("./lib/test.cjs");
|
|
|
|
const {page_params} = require("./lib/zpage_params.cjs");
|
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");
|
2024-10-09 22:44:13 +02:00
|
|
|
const {set_current_user, set_realm} = zrequire("state_data");
|
2023-08-03 16:06:40 +02:00
|
|
|
const user_groups = zrequire("user_groups");
|
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
|
|
|
const user_settings = {};
|
|
|
|
initialize_user_settings({user_settings});
|
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
|
|
|
};
|
|
|
|
|
2024-09-06 16:41:41 +02:00
|
|
|
const group_permission_settings = mock_esm("../src/group_permission_settings", {});
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_can_change_email", ({override}) => {
|
2022-12-09 17:34:00 +01:00
|
|
|
const can_change_email = settings_data.user_can_change_email;
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", true);
|
2022-12-09 17:34:00 +01:00
|
|
|
assert.equal(can_change_email(), true);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", false);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_email_changes_disabled", true);
|
2022-12-09 17:34:00 +01:00
|
|
|
assert.equal(can_change_email(), false);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_email_changes_disabled", false);
|
2022-12-09 17:34:00 +01:00
|
|
|
assert.equal(can_change_email(), true);
|
|
|
|
});
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_can_change_name", ({override}) => {
|
2021-03-21 16:46:13 +01:00
|
|
|
const can_change_name = settings_data.user_can_change_name;
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", true);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), true);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", false);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_name_changes_disabled", true);
|
|
|
|
override(realm, "server_name_changes_disabled", false);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), false);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_name_changes_disabled", false);
|
|
|
|
override(realm, "server_name_changes_disabled", false);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), true);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_name_changes_disabled", false);
|
|
|
|
override(realm, "server_name_changes_disabled", true);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_name(), false);
|
|
|
|
});
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_can_change_avatar", ({override}) => {
|
2021-03-21 16:46:13 +01:00
|
|
|
const can_change_avatar = settings_data.user_can_change_avatar;
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", true);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), true);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", false);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_avatar_changes_disabled", true);
|
|
|
|
override(realm, "server_avatar_changes_disabled", false);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), false);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_avatar_changes_disabled", false);
|
|
|
|
override(realm, "server_avatar_changes_disabled", false);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), true);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_avatar_changes_disabled", false);
|
|
|
|
override(realm, "server_avatar_changes_disabled", true);
|
2021-03-21 16:46:13 +01:00
|
|
|
assert.equal(can_change_avatar(), false);
|
|
|
|
});
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_can_change_logo", ({override}) => {
|
2020-06-17 07:43:53 +02:00
|
|
|
const can_change_logo = settings_data.user_can_change_logo;
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", true);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "zulip_plan_is_not_limited", true);
|
2020-06-17 07:43:53 +02:00
|
|
|
assert.equal(can_change_logo(), true);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", false);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "zulip_plan_is_not_limited", false);
|
2020-06-17 07:43:53 +02:00
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", true);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "zulip_plan_is_not_limited", false);
|
2020-06-17 07:43:53 +02:00
|
|
|
assert.equal(can_change_logo(), false);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", false);
|
2024-10-09 22:20:06 +02:00
|
|
|
override(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) {
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test(label, ({override}) => {
|
|
|
|
override(current_user, "is_admin", true);
|
2024-10-10 00:50:57 +02:00
|
|
|
override(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-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_admin", false);
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_moderator", true);
|
2024-10-10 00:50:57 +02:00
|
|
|
override(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-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_moderator", false);
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_guest", true);
|
2024-10-10 00:50:57 +02:00
|
|
|
override(realm, policy, settings_config.common_policy_values.by_members.code);
|
2021-04-30 09:24:29 +02:00
|
|
|
assert.equal(validation_func(), false);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(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-10-10 00:50:57 +02:00
|
|
|
override(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-10-10 00:50:57 +02:00
|
|
|
override(realm, policy, settings_config.common_policy_values.by_full_members.code);
|
2024-10-09 21:21:41 +02:00
|
|
|
override(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-10-09 22:20:06 +02:00
|
|
|
override(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-05-26 21:20:11 +02:00
|
|
|
|
2024-10-13 09:09:11 +02:00
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_add_custom_emoji_group",
|
|
|
|
settings_data.user_can_add_custom_emoji,
|
|
|
|
);
|
|
|
|
|
2024-08-15 07:29:15 +02:00
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_delete_any_message_group",
|
|
|
|
settings_data.user_can_delete_any_message,
|
|
|
|
);
|
|
|
|
|
2024-09-11 19:13:37 +02:00
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_delete_own_message_group",
|
2021-06-23 12:53:38 +02:00
|
|
|
settings_data.user_can_delete_own_message,
|
|
|
|
);
|
|
|
|
|
2024-10-16 18:09:38 +02:00
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_move_messages_between_channels_group",
|
|
|
|
settings_data.user_can_move_messages_between_streams,
|
|
|
|
);
|
|
|
|
|
2024-10-27 17:01:01 +01:00
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_move_messages_between_topics_group",
|
|
|
|
settings_data.user_can_move_messages_to_another_topic,
|
|
|
|
);
|
|
|
|
|
2024-10-09 21:10:22 +02:00
|
|
|
run_test("using_dark_theme", ({override}) => {
|
|
|
|
override(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);
|
|
|
|
|
2024-10-09 21:10:22 +02:00
|
|
|
override(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-10-09 21:10:22 +02:00
|
|
|
override(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
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_can_invite_others_to_realm_nobody_case", ({override}) => {
|
|
|
|
override(current_user, "is_admin", true);
|
|
|
|
override(current_user, "is_guest", false);
|
2024-10-10 00:50:57 +02:00
|
|
|
override(
|
|
|
|
realm,
|
|
|
|
"realm_invite_to_realm_policy",
|
|
|
|
settings_config.email_invite_to_realm_policy_values.nobody.code,
|
|
|
|
);
|
2023-06-26 23:38:08 +02:00
|
|
|
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
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_email_not_configured", ({override}) => {
|
2023-02-13 19:42:58 +01:00
|
|
|
const user_email_not_configured = settings_data.user_email_not_configured;
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_owner", false);
|
2023-02-13 19:42:58 +01:00
|
|
|
assert.equal(user_email_not_configured(), false);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "is_owner", true);
|
|
|
|
override(current_user, "delivery_email", "");
|
2023-02-13 19:42:58 +01:00
|
|
|
assert.equal(user_email_not_configured(), true);
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(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-07-26 05:30:36 +02:00
|
|
|
function test_realm_group_settings(setting_name, validation_func) {
|
2024-10-09 21:21:41 +02:00
|
|
|
with_overrides(({override}) => {
|
|
|
|
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]),
|
|
|
|
};
|
|
|
|
|
|
|
|
group_permission_settings.get_group_permission_setting_config = () => ({
|
|
|
|
allow_everyone_group: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
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-10-09 21:21:41 +02:00
|
|
|
page_params.is_spectator = false;
|
|
|
|
override(current_user, "is_guest", false);
|
2024-10-10 00:50:57 +02:00
|
|
|
override(realm, setting_name, 1);
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", admin_user_id);
|
|
|
|
assert.equal(validation_func(), true);
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", moderator_user_id);
|
|
|
|
assert.equal(validation_func(), false);
|
2024-07-26 05:30:36 +02:00
|
|
|
|
2024-10-10 00:50:57 +02:00
|
|
|
override(realm, setting_name, 2);
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", moderator_user_id);
|
|
|
|
assert.equal(validation_func(), true);
|
2024-07-26 05:30:36 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", member_user_id);
|
|
|
|
assert.equal(validation_func(), false);
|
2024-09-06 16:41:41 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", moderator_user_id);
|
|
|
|
override(current_user, "is_guest", true);
|
|
|
|
assert.equal(validation_func(), false);
|
2024-09-06 16:41:41 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
group_permission_settings.get_group_permission_setting_config = () => ({
|
|
|
|
allow_everyone_group: true,
|
|
|
|
});
|
|
|
|
assert.equal(validation_func(), true);
|
2024-09-06 16:41:41 +02:00
|
|
|
});
|
2024-06-19 15:38:07 +02:00
|
|
|
}
|
2023-08-03 16:06:40 +02:00
|
|
|
|
2024-07-26 05:30:36 +02:00
|
|
|
run_test("user_can_create_multiuse_invite", () => {
|
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_create_multiuse_invite_group",
|
|
|
|
settings_data.user_can_create_multiuse_invite,
|
|
|
|
);
|
|
|
|
});
|
2023-09-22 19:32:14 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("can_manage_user_group", ({override}) => {
|
2023-08-08 16:10:17 +02:00
|
|
|
const admins = {
|
|
|
|
description: "Administrators",
|
|
|
|
name: "role:administrators",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([1]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const moderators = {
|
|
|
|
description: "Moderators",
|
|
|
|
name: "role:moderators",
|
|
|
|
id: 2,
|
|
|
|
members: new Set([2]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1]),
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const members = {
|
|
|
|
description: "Members",
|
|
|
|
name: "role:members",
|
|
|
|
id: 3,
|
2024-09-16 21:02:46 +02:00
|
|
|
members: new Set([3, 4]),
|
2023-08-08 16:10:17 +02:00
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1, 2]),
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 4,
|
|
|
|
};
|
|
|
|
const nobody = {
|
|
|
|
description: "Nobody",
|
|
|
|
name: "role:nobody",
|
|
|
|
id: 4,
|
|
|
|
members: new Set([]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 2,
|
|
|
|
};
|
2023-09-22 19:32:14 +02:00
|
|
|
const students = {
|
|
|
|
description: "Students group",
|
|
|
|
name: "Students",
|
2023-08-08 16:10:17 +02:00
|
|
|
id: 5,
|
2023-09-22 19:32:14 +02:00
|
|
|
members: new Set([1, 2]),
|
|
|
|
is_system_group: false,
|
|
|
|
direct_subgroup_ids: new Set([4, 5]),
|
2024-09-25 11:51:28 +02:00
|
|
|
can_manage_group: {
|
|
|
|
direct_members: [4],
|
|
|
|
direct_subgroups: [],
|
|
|
|
},
|
2023-08-08 16:10:17 +02:00
|
|
|
can_mention_group: 3,
|
2024-09-16 21:02:46 +02:00
|
|
|
creator_id: 4,
|
2023-09-22 19:32:14 +02:00
|
|
|
};
|
|
|
|
user_groups.initialize({
|
2023-08-08 16:10:17 +02:00
|
|
|
realm_user_groups: [admins, moderators, members, nobody, students],
|
2023-09-22 19:32:14 +02:00
|
|
|
});
|
|
|
|
|
2024-06-12 12:04:08 +02:00
|
|
|
page_params.is_spectator = true;
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(!settings_data.can_manage_user_group(students.id));
|
2023-09-22 19:32:14 +02:00
|
|
|
|
2024-06-12 12:04:08 +02:00
|
|
|
page_params.is_spectator = false;
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_can_manage_all_groups", admins.id);
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 3);
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(!settings_data.can_manage_user_group(students.id));
|
2023-09-22 19:32:14 +02:00
|
|
|
|
2024-09-16 21:02:46 +02:00
|
|
|
// non-admin group_creator
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 4);
|
2024-09-16 21:02:46 +02:00
|
|
|
assert.ok(settings_data.can_manage_user_group(students.id));
|
|
|
|
|
|
|
|
// admin user
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 1);
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(settings_data.can_manage_user_group(students.id));
|
2023-09-22 19:32:14 +02:00
|
|
|
|
2024-09-16 21:02:46 +02:00
|
|
|
// moderator user
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 2);
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(!settings_data.can_manage_user_group(students.id));
|
2023-08-08 16:10:17 +02:00
|
|
|
|
2024-10-10 13:35:44 +02:00
|
|
|
// User with role member and not part of the group.
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_can_manage_all_groups", members.id);
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 3);
|
2024-10-10 13:35:44 +02:00
|
|
|
assert.ok(settings_data.can_manage_user_group(students.id));
|
2023-09-22 19:32:14 +02:00
|
|
|
|
2024-10-10 13:35:44 +02:00
|
|
|
// User with role member and part of the group.
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 2);
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(settings_data.can_manage_user_group(students.id));
|
2023-08-08 16:10:17 +02:00
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_can_manage_all_groups", admins.id);
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 2);
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(!settings_data.can_manage_user_group(students.id));
|
2023-08-08 16:10:17 +02:00
|
|
|
|
|
|
|
const event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_manage_group: members.id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(settings_data.can_manage_user_group(students.id));
|
2023-08-08 16:10:17 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 3);
|
2024-09-18 10:54:19 +02:00
|
|
|
assert.ok(settings_data.can_manage_user_group(students.id));
|
2023-09-22 19:32:14 +02:00
|
|
|
});
|
2023-09-25 10:15:19 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("can_join_user_group", ({override}) => {
|
2024-10-02 13:13:47 +02:00
|
|
|
const admins = {
|
|
|
|
description: "Administrators",
|
|
|
|
name: "role:administrators",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([1]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const moderators = {
|
|
|
|
description: "Moderators",
|
|
|
|
name: "role:moderators",
|
|
|
|
id: 2,
|
|
|
|
members: new Set([2]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const members = {
|
|
|
|
description: "Members",
|
|
|
|
name: "role:members",
|
|
|
|
id: 3,
|
|
|
|
members: new Set([3, 4]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1, 2]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 4,
|
|
|
|
};
|
|
|
|
const nobody = {
|
|
|
|
description: "Nobody",
|
|
|
|
name: "role:nobody",
|
|
|
|
id: 4,
|
|
|
|
members: new Set([]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 2,
|
|
|
|
};
|
|
|
|
const students = {
|
|
|
|
description: "Students group",
|
|
|
|
name: "Students",
|
|
|
|
id: 5,
|
|
|
|
members: new Set([1, 2]),
|
|
|
|
is_system_group: false,
|
|
|
|
direct_subgroup_ids: new Set([4, 5]),
|
|
|
|
can_join_group: 1,
|
|
|
|
can_manage_group: {
|
|
|
|
direct_members: [4],
|
|
|
|
direct_subgroups: [],
|
|
|
|
},
|
|
|
|
can_mention_group: 3,
|
|
|
|
creator_id: 4,
|
|
|
|
};
|
|
|
|
user_groups.initialize({
|
|
|
|
realm_user_groups: [admins, moderators, members, nobody, students],
|
|
|
|
});
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_can_manage_all_groups", nobody.id);
|
2024-10-02 13:13:47 +02:00
|
|
|
|
|
|
|
page_params.is_spectator = true;
|
|
|
|
assert.ok(!settings_data.can_join_user_group(students.id));
|
|
|
|
|
|
|
|
page_params.is_spectator = false;
|
|
|
|
// admin user
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 1);
|
2024-10-02 13:13:47 +02:00
|
|
|
assert.ok(settings_data.can_join_user_group(students.id));
|
|
|
|
|
|
|
|
// moderator user
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 2);
|
2024-10-02 13:13:47 +02:00
|
|
|
assert.ok(!settings_data.can_join_user_group(students.id));
|
|
|
|
|
|
|
|
let event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_join_group: moderators.id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
|
|
|
assert.ok(settings_data.can_join_user_group(students.id));
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 1);
|
2024-10-02 13:13:47 +02:00
|
|
|
assert.ok(settings_data.can_join_user_group(students.id));
|
|
|
|
|
|
|
|
// Some other user.
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 5);
|
2024-10-02 13:13:47 +02:00
|
|
|
assert.ok(!settings_data.can_join_user_group(students.id));
|
|
|
|
|
|
|
|
event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_join_group: {
|
|
|
|
direct_members: [5],
|
|
|
|
direct_subgroups: [admins.id],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
|
|
|
assert.ok(settings_data.can_join_user_group(students.id));
|
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 2);
|
2024-10-02 13:13:47 +02:00
|
|
|
assert.ok(!settings_data.can_join_user_group(students.id));
|
|
|
|
|
|
|
|
// User can join the group if they can add anyone in the group which
|
|
|
|
// depends on can_manage_group and realm.can_manage_all_groups settings.
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 4);
|
2024-10-02 13:13:47 +02:00
|
|
|
assert.ok(settings_data.can_join_user_group(students.id));
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_can_manage_all_groups", moderators.id);
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", 2);
|
2024-10-02 13:13:47 +02:00
|
|
|
assert.ok(settings_data.can_join_user_group(students.id));
|
|
|
|
});
|
|
|
|
|
2024-10-14 13:29:10 +02:00
|
|
|
run_test("can_leave_user_group", ({override}) => {
|
|
|
|
const admins = {
|
|
|
|
description: "Administrators",
|
|
|
|
name: "role:administrators",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([1]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_leave_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const moderators = {
|
|
|
|
description: "Moderators",
|
|
|
|
name: "role:moderators",
|
|
|
|
id: 2,
|
|
|
|
members: new Set([2]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_leave_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const members = {
|
|
|
|
description: "Members",
|
|
|
|
name: "role:members",
|
|
|
|
id: 3,
|
|
|
|
members: new Set([3, 4]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1, 2]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_leave_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 4,
|
|
|
|
};
|
|
|
|
const nobody = {
|
|
|
|
description: "Nobody",
|
|
|
|
name: "role:nobody",
|
|
|
|
id: 4,
|
|
|
|
members: new Set([]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_join_group: 4,
|
|
|
|
can_leave_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 2,
|
|
|
|
};
|
|
|
|
const students = {
|
|
|
|
description: "Students group",
|
|
|
|
name: "Students",
|
|
|
|
id: 5,
|
|
|
|
members: new Set([1, 2]),
|
|
|
|
is_system_group: false,
|
|
|
|
direct_subgroup_ids: new Set([4, 5]),
|
|
|
|
can_join_group: 1,
|
|
|
|
can_leave_group: 1,
|
|
|
|
can_manage_group: {
|
|
|
|
direct_members: [4],
|
|
|
|
direct_subgroups: [],
|
|
|
|
},
|
|
|
|
can_mention_group: 3,
|
|
|
|
creator_id: 4,
|
|
|
|
};
|
|
|
|
user_groups.initialize({
|
|
|
|
realm_user_groups: [admins, moderators, members, nobody, students],
|
|
|
|
});
|
|
|
|
override(realm, "realm_can_manage_all_groups", nobody.id);
|
|
|
|
|
|
|
|
page_params.is_spectator = true;
|
|
|
|
assert.ok(!settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
page_params.is_spectator = false;
|
|
|
|
// admin user
|
|
|
|
override(current_user, "user_id", 1);
|
|
|
|
assert.ok(settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
// moderator user
|
|
|
|
override(current_user, "user_id", 2);
|
|
|
|
assert.ok(!settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
let event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_leave_group: moderators.id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
|
|
|
assert.ok(settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
override(current_user, "user_id", 1);
|
|
|
|
assert.ok(settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
// Some other user.
|
|
|
|
override(current_user, "user_id", 5);
|
|
|
|
assert.ok(!settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_leave_group: {
|
|
|
|
direct_members: [5],
|
|
|
|
direct_subgroups: [admins.id],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
|
|
|
assert.ok(settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
override(current_user, "user_id", 2);
|
|
|
|
assert.ok(!settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
// User can leave the group if they can manage the group which
|
|
|
|
// depends on can_manage_group and realm.can_manage_all_groups settings.
|
|
|
|
override(current_user, "user_id", 4);
|
|
|
|
assert.ok(settings_data.can_leave_user_group(students.id));
|
|
|
|
|
|
|
|
override(realm, "realm_can_manage_all_groups", moderators.id);
|
|
|
|
override(current_user, "user_id", 2);
|
|
|
|
assert.ok(settings_data.can_leave_user_group(students.id));
|
|
|
|
});
|
|
|
|
|
2024-10-09 09:37:35 +02:00
|
|
|
run_test("can_add_members_user_group", () => {
|
|
|
|
const admins = {
|
|
|
|
description: "Administrators",
|
|
|
|
name: "role:administrators",
|
|
|
|
id: 1,
|
|
|
|
members: new Set([1]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_add_members_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const moderators = {
|
|
|
|
description: "Moderators",
|
|
|
|
name: "role:moderators",
|
|
|
|
id: 2,
|
|
|
|
members: new Set([2]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1]),
|
|
|
|
can_add_members_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 1,
|
|
|
|
};
|
|
|
|
const members = {
|
|
|
|
description: "Members",
|
|
|
|
name: "role:members",
|
|
|
|
id: 3,
|
|
|
|
members: new Set([3, 4]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([1, 2]),
|
|
|
|
can_add_members_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 4,
|
|
|
|
};
|
|
|
|
const nobody = {
|
|
|
|
description: "Nobody",
|
|
|
|
name: "role:nobody",
|
|
|
|
id: 4,
|
|
|
|
members: new Set([]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
can_add_members_group: 4,
|
|
|
|
can_manage_group: 4,
|
|
|
|
can_mention_group: 2,
|
|
|
|
};
|
|
|
|
const students = {
|
|
|
|
description: "Students group",
|
|
|
|
name: "Students",
|
|
|
|
id: 5,
|
|
|
|
members: new Set([1, 2]),
|
|
|
|
is_system_group: false,
|
|
|
|
direct_subgroup_ids: new Set([4, 5]),
|
|
|
|
can_add_members_group: 1,
|
|
|
|
can_manage_group: {
|
|
|
|
direct_members: [6],
|
|
|
|
direct_subgroups: [],
|
|
|
|
},
|
|
|
|
can_mention_group: 3,
|
|
|
|
creator_id: 4,
|
|
|
|
};
|
|
|
|
user_groups.initialize({
|
|
|
|
realm_user_groups: [admins, moderators, members, nobody, students],
|
|
|
|
});
|
|
|
|
realm.realm_can_manage_all_groups = nobody.id;
|
|
|
|
|
|
|
|
page_params.is_spectator = true;
|
|
|
|
assert.ok(!settings_data.can_add_members_to_user_group(students.id));
|
|
|
|
|
|
|
|
page_params.is_spectator = false;
|
|
|
|
// admin user
|
|
|
|
current_user.user_id = 1;
|
|
|
|
assert.ok(settings_data.can_add_members_to_user_group(students.id));
|
|
|
|
|
|
|
|
// moderator user
|
|
|
|
current_user.user_id = 2;
|
|
|
|
assert.ok(!settings_data.can_add_members_to_user_group(students.id));
|
|
|
|
|
|
|
|
let event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_add_members_group: moderators.id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
|
|
|
assert.ok(settings_data.can_add_members_to_user_group(students.id));
|
|
|
|
|
|
|
|
// Some other user.
|
|
|
|
current_user.user_id = 5;
|
|
|
|
assert.ok(!settings_data.can_add_members_to_user_group(students.id));
|
|
|
|
|
|
|
|
event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_add_members_group: {
|
|
|
|
direct_members: [5],
|
|
|
|
direct_subgroups: [admins.id],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
|
|
|
assert.ok(settings_data.can_add_members_to_user_group(students.id));
|
|
|
|
|
|
|
|
// Users with permission to manage the group should be able to add
|
|
|
|
// members to the group without adding themselves to
|
|
|
|
// can_add_members_group.
|
|
|
|
current_user.user_id = 4;
|
|
|
|
assert.ok(!settings_data.can_add_members_to_user_group(students.id));
|
|
|
|
event = {
|
|
|
|
group_id: students.id,
|
|
|
|
data: {
|
|
|
|
can_manage_group: {
|
|
|
|
direct_members: [4],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
user_groups.update(event);
|
|
|
|
assert.ok(settings_data.can_add_members_to_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
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_can_access_all_other_users", ({override}) => {
|
2023-11-28 18:24:43 +01:00
|
|
|
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-10-09 22:20:06 +02:00
|
|
|
override(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-10-09 21:21:41 +02:00
|
|
|
override(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-10-09 21:21:41 +02:00
|
|
|
override(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-10-09 22:20:06 +02:00
|
|
|
override(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-07-26 05:30:36 +02:00
|
|
|
run_test("user_can_create_public_streams", () => {
|
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_create_public_channel_group",
|
|
|
|
settings_data.user_can_create_public_streams,
|
|
|
|
);
|
|
|
|
});
|
2024-06-17 16:06:49 +02:00
|
|
|
|
2024-09-12 04:54:42 +02:00
|
|
|
run_test("user_can_create_user_groups", () => {
|
|
|
|
test_realm_group_settings("realm_can_create_groups", settings_data.user_can_create_user_groups);
|
|
|
|
});
|
|
|
|
|
2024-09-18 10:54:19 +02:00
|
|
|
run_test("user_can_manage_all_groups", () => {
|
2024-09-16 21:02:46 +02:00
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_manage_all_groups",
|
2024-09-18 10:54:19 +02:00
|
|
|
settings_data.user_can_manage_all_groups,
|
2024-09-16 21:02:46 +02:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2024-07-26 05:30:36 +02:00
|
|
|
run_test("user_can_create_private_streams", () => {
|
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_create_private_channel_group",
|
|
|
|
settings_data.user_can_create_private_streams,
|
|
|
|
);
|
|
|
|
});
|
2024-07-26 05:42:14 +02:00
|
|
|
|
2024-10-09 21:21:41 +02:00
|
|
|
run_test("user_can_create_web_public_streams", ({override}) => {
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "server_web_public_streams_enabled", true);
|
|
|
|
override(realm, "realm_enable_spectator_access", true);
|
2024-07-26 05:42:14 +02:00
|
|
|
|
|
|
|
test_realm_group_settings(
|
|
|
|
"realm_can_create_web_public_channel_group",
|
|
|
|
settings_data.user_can_create_web_public_streams,
|
|
|
|
);
|
|
|
|
const owner_user_id = 4;
|
|
|
|
const owners = {
|
|
|
|
name: "Admins",
|
|
|
|
id: 3,
|
|
|
|
members: new Set([owner_user_id]),
|
|
|
|
is_system_group: true,
|
|
|
|
direct_subgroup_ids: new Set([]),
|
|
|
|
};
|
2024-10-09 21:21:41 +02:00
|
|
|
override(current_user, "user_id", owner_user_id);
|
2024-07-26 05:42:14 +02:00
|
|
|
user_groups.initialize({realm_user_groups: [owners]});
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "server_web_public_streams_enabled", true);
|
|
|
|
override(realm, "realm_enable_spectator_access", true);
|
|
|
|
override(realm, "realm_can_create_web_public_channel_group", owners.id);
|
2024-07-26 05:42:14 +02:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), true);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_enable_spectator_access", false);
|
|
|
|
override(realm, "server_web_public_streams_enabled", true);
|
2024-07-26 05:42:14 +02:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_enable_spectator_access", true);
|
|
|
|
override(realm, "server_web_public_streams_enabled", false);
|
2024-07-26 05:42:14 +02:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
|
2024-10-09 22:20:06 +02:00
|
|
|
override(realm, "realm_enable_spectator_access", false);
|
|
|
|
override(realm, "server_web_public_streams_enabled", false);
|
2024-07-26 05:42:14 +02:00
|
|
|
assert.equal(settings_data.user_can_create_web_public_streams(), false);
|
|
|
|
});
|
2024-10-09 18:30:33 +02:00
|
|
|
|
|
|
|
run_test("guests_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]});
|
|
|
|
realm.realm_can_access_all_users_group = members.id;
|
|
|
|
assert.ok(!settings_data.guests_can_access_all_other_users());
|
|
|
|
|
|
|
|
user_groups.initialize({realm_user_groups: [members, everyone]});
|
|
|
|
realm.realm_can_access_all_users_group = everyone.id;
|
|
|
|
assert.ok(settings_data.guests_can_access_all_other_users());
|
|
|
|
});
|