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 {mock_esm, zrequire} = require("./lib/namespace");
|
2023-12-14 23:51:33 +01:00
|
|
|
const {run_test, noop} = require("./lib/test");
|
2023-02-22 23:04:10 +01:00
|
|
|
const blueslip = require("./lib/zblueslip");
|
2023-07-17 18:01:16 +02:00
|
|
|
const $ = require("./lib/zjquery");
|
2023-02-22 23:04:10 +01:00
|
|
|
const {page_params} = require("./lib/zpage_params");
|
2017-08-09 19:31:57 +02:00
|
|
|
|
2023-02-22 23:04:10 +01:00
|
|
|
const message_live_update = mock_esm("../src/message_live_update");
|
|
|
|
const settings_account = mock_esm("../src/settings_account", {
|
2023-10-30 12:50:40 +01:00
|
|
|
maybe_update_deactivate_account_button() {},
|
2021-03-07 13:57:14 +01:00
|
|
|
update_email() {},
|
|
|
|
update_full_name() {},
|
2023-01-02 19:45:30 +01:00
|
|
|
update_account_settings_display() {},
|
2021-03-07 13:57:14 +01:00
|
|
|
});
|
2023-10-30 12:50:40 +01:00
|
|
|
const settings_users = mock_esm("../src/settings_users", {
|
|
|
|
update_user_data() {},
|
|
|
|
update_view_on_deactivate() {},
|
|
|
|
});
|
|
|
|
const stream_events = mock_esm("../src/stream_events");
|
2021-03-07 13:57:14 +01:00
|
|
|
|
2023-10-05 10:20:16 +02:00
|
|
|
mock_esm("../src/activity_ui", {
|
2020-07-20 22:18:43 +02:00
|
|
|
redraw() {},
|
2017-01-21 16:49:27 +01:00
|
|
|
});
|
2023-10-06 09:37:10 +02:00
|
|
|
mock_esm("../src/compose_state", {
|
2021-03-07 13:57:14 +01:00
|
|
|
update_email() {},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/narrow_state", {
|
2021-03-07 13:57:14 +01:00
|
|
|
update_email() {},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/pm_list", {
|
2021-03-07 13:57:14 +01:00
|
|
|
update_private_messages() {},
|
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/settings_linkifiers", {
|
2020-07-20 22:18:43 +02:00
|
|
|
maybe_disable_widgets() {},
|
2018-12-08 18:16:37 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/settings_org", {
|
2020-07-20 22:18:43 +02:00
|
|
|
maybe_disable_widgets() {},
|
2017-04-08 20:08:35 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/settings_profile_fields", {
|
2020-07-20 22:18:43 +02:00
|
|
|
maybe_disable_widgets() {},
|
2021-09-16 19:18:39 +02:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/settings_realm_user_settings_defaults", {
|
2021-09-16 19:18:39 +02:00
|
|
|
maybe_disable_widgets() {},
|
2018-12-06 18:23:57 +01:00
|
|
|
});
|
2023-02-22 23:04:10 +01:00
|
|
|
mock_esm("../src/settings_streams", {
|
2020-07-20 22:18:43 +02:00
|
|
|
maybe_disable_widgets() {},
|
2018-12-08 18:16:37 +01:00
|
|
|
});
|
|
|
|
|
2021-03-25 22:35:45 +01:00
|
|
|
page_params.is_admin = true;
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2020-12-01 23:21:38 +01:00
|
|
|
const people = zrequire("people");
|
|
|
|
const settings_config = zrequire("settings_config");
|
|
|
|
const user_events = zrequire("user_events");
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const me = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "me@example.com",
|
2017-01-21 16:49:27 +01:00
|
|
|
user_id: 30,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Me Myself",
|
2017-01-21 16:49:27 +01:00
|
|
|
is_admin: true,
|
2021-05-28 12:51:50 +02:00
|
|
|
role: settings_config.user_role_values.member.code,
|
2017-01-21 16:49:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
function initialize() {
|
|
|
|
people.init();
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(me);
|
2017-01-21 16:49:27 +01:00
|
|
|
people.initialize_current_user(me.user_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("updates", () => {
|
2019-11-02 00:06:25 +01:00
|
|
|
let person;
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const isaac = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "isaac@example.com",
|
2021-10-26 15:43:39 +02:00
|
|
|
delivery_email: null,
|
2017-01-21 16:49:27 +01:00
|
|
|
user_id: 32,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Isaac Newton",
|
2017-01-21 16:49:27 +01:00
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(isaac);
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
user_events.update_person({
|
|
|
|
user_id: isaac.user_id,
|
|
|
|
role: settings_config.user_role_values.guest.code,
|
|
|
|
});
|
2018-10-29 20:49:07 +01:00
|
|
|
person = people.get_by_email(isaac.email);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(person.is_guest);
|
2021-06-03 16:42:03 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.guest.code);
|
2020-07-15 00:34:28 +02:00
|
|
|
user_events.update_person({
|
|
|
|
user_id: isaac.user_id,
|
|
|
|
role: settings_config.user_role_values.member.code,
|
|
|
|
});
|
2018-10-29 20:49:07 +01:00
|
|
|
person = people.get_by_email(isaac.email);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!person.is_guest);
|
2021-06-03 16:42:03 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.member.code);
|
2018-10-29 20:49:07 +01:00
|
|
|
|
2021-04-22 21:37:04 +02:00
|
|
|
user_events.update_person({
|
|
|
|
user_id: isaac.user_id,
|
|
|
|
role: settings_config.user_role_values.moderator.code,
|
|
|
|
});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.is_moderator, true);
|
2021-06-03 16:42:03 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.moderator.code);
|
2021-04-22 21:37:04 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
user_events.update_person({
|
|
|
|
user_id: isaac.user_id,
|
|
|
|
role: settings_config.user_role_values.admin.code,
|
|
|
|
});
|
2017-01-21 16:49:27 +01:00
|
|
|
person = people.get_by_email(isaac.email);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.full_name, "Isaac Newton");
|
2021-04-22 21:37:04 +02:00
|
|
|
assert.equal(person.is_moderator, false);
|
2017-01-21 16:49:27 +01:00
|
|
|
assert.equal(person.is_admin, true);
|
2021-06-03 16:42:03 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.admin.code);
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
user_events.update_person({
|
|
|
|
user_id: isaac.user_id,
|
|
|
|
role: settings_config.user_role_values.owner.code,
|
|
|
|
});
|
2020-06-03 23:30:34 +02:00
|
|
|
assert.equal(person.is_admin, true);
|
|
|
|
assert.equal(person.is_owner, true);
|
2021-06-03 16:42:03 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.owner.code);
|
2020-06-03 23:30:34 +02:00
|
|
|
|
2021-05-28 12:51:50 +02:00
|
|
|
user_events.update_person({user_id: me.user_id, is_billing_admin: true});
|
|
|
|
person = people.get_by_email(me.email);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(person.is_billing_admin);
|
2021-05-28 12:51:50 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.member.code);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(page_params.is_billing_admin);
|
2021-05-28 12:51:50 +02:00
|
|
|
|
|
|
|
user_events.update_person({user_id: me.user_id, is_billing_admin: false});
|
|
|
|
person = people.get_by_email(me.email);
|
|
|
|
assert.equal(person.user_id, me.user_id);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!person.is_billing_admin);
|
2021-05-28 12:51:50 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.member.code);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!page_params.is_billing_admin);
|
2021-05-28 12:51:50 +02:00
|
|
|
|
|
|
|
user_events.update_person({user_id: isaac.user_id, is_billing_admin: false});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.user_id, isaac.user_id);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!person.is_billing_admin);
|
2021-05-28 12:51:50 +02:00
|
|
|
assert.equal(person.role, settings_config.user_role_values.owner.code);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!page_params.is_billing_admin);
|
2021-05-28 12:51:50 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let user_id;
|
|
|
|
let full_name;
|
2021-02-23 14:37:26 +01:00
|
|
|
message_live_update.update_user_full_name = (user_id_arg, full_name_arg) => {
|
2017-01-24 19:12:21 +01:00
|
|
|
user_id = user_id_arg;
|
|
|
|
full_name = full_name_arg;
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: isaac.user_id, full_name: "Sir Isaac"});
|
2017-01-21 16:49:27 +01:00
|
|
|
person = people.get_by_email(isaac.email);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.full_name, "Sir Isaac");
|
2017-01-21 16:49:27 +01:00
|
|
|
assert.equal(person.is_admin, true);
|
2017-01-24 19:12:21 +01:00
|
|
|
assert.equal(user_id, isaac.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(full_name, "Sir Isaac");
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
user_events.update_person({
|
|
|
|
user_id: me.user_id,
|
|
|
|
role: settings_config.user_role_values.member.code,
|
|
|
|
});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!page_params.is_admin);
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: me.user_id, full_name: "Me V2"});
|
|
|
|
assert.equal(people.my_full_name(), "Me V2");
|
2017-01-24 19:12:21 +01:00
|
|
|
assert.equal(user_id, me.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(full_name, "Me V2");
|
2017-01-21 16:49:27 +01:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: isaac.user_id, new_email: "newton@example.com"});
|
2020-02-05 14:30:59 +01:00
|
|
|
person = people.get_by_user_id(isaac.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.email, "newton@example.com");
|
|
|
|
assert.equal(person.full_name, "Sir Isaac");
|
2017-06-20 23:41:04 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: me.user_id, new_email: "meforu@example.com"});
|
2020-02-05 14:30:59 +01:00
|
|
|
person = people.get_by_user_id(me.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.email, "meforu@example.com");
|
|
|
|
assert.equal(person.full_name, "Me V2");
|
2017-06-20 23:41:04 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let avatar_url;
|
2021-02-23 14:37:26 +01:00
|
|
|
message_live_update.update_avatar = (user_id_arg, avatar_url_arg) => {
|
2017-06-20 23:41:04 +02:00
|
|
|
user_id = user_id_arg;
|
|
|
|
avatar_url = avatar_url_arg;
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: isaac.user_id, full_name: "Sir Isaac"});
|
2017-06-20 23:41:04 +02:00
|
|
|
person = people.get_by_email(isaac.email);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.full_name, "Sir Isaac");
|
2017-06-20 23:41:04 +02:00
|
|
|
assert.equal(person.is_admin, true);
|
|
|
|
assert.equal(user_id, isaac.user_id);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(full_name, "Sir Isaac");
|
2017-06-20 23:41:04 +02:00
|
|
|
|
2021-10-26 15:43:39 +02:00
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.delivery_email, null);
|
|
|
|
user_events.update_person({
|
|
|
|
user_id: isaac.user_id,
|
|
|
|
delivery_email: "isaac-delivery@example.com",
|
|
|
|
});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.delivery_email, "isaac-delivery@example.com");
|
|
|
|
|
|
|
|
user_events.update_person({user_id: isaac.user_id, delivery_email: null});
|
|
|
|
person = people.get_by_email(isaac.email);
|
|
|
|
assert.equal(person.delivery_email, null);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: isaac.user_id, avatar_url: "http://gravatar.com/123456"});
|
2017-06-20 23:41:04 +02:00
|
|
|
person = people.get_by_email(isaac.email);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.full_name, "Sir Isaac");
|
2017-06-20 23:41:04 +02:00
|
|
|
assert.equal(user_id, isaac.user_id);
|
|
|
|
assert.equal(person.avatar_url, avatar_url);
|
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
$("#personal-menu .header-button-avatar").css = noop;
|
2023-07-17 18:01:16 +02:00
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: me.user_id, avatar_url: "http://gravatar.com/789456"});
|
2017-06-20 23:41:04 +02:00
|
|
|
person = people.get_by_email(me.email);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.full_name, "Me V2");
|
2017-06-20 23:41:04 +02:00
|
|
|
assert.equal(user_id, me.user_id);
|
|
|
|
assert.equal(person.avatar_url, avatar_url);
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: me.user_id, timezone: "UTC"});
|
2017-06-20 23:41:04 +02:00
|
|
|
person = people.get_by_email(me.email);
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(person.timezone);
|
2017-06-20 23:41:04 +02:00
|
|
|
|
2023-04-24 15:57:45 +02:00
|
|
|
blueslip.expect("error", "Got update_person event for unexpected user");
|
2023-06-16 15:23:45 +02:00
|
|
|
blueslip.expect("error", "Unknown user_id in maybe_get_user_by_id");
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(!user_events.update_person({user_id: 29, full_name: "Sir Isaac Newton"}));
|
2017-06-20 23:41:04 +02:00
|
|
|
|
2018-03-10 14:41:44 +01:00
|
|
|
me.profile_data = {};
|
2020-07-15 00:34:28 +02:00
|
|
|
user_events.update_person({
|
|
|
|
user_id: me.user_id,
|
|
|
|
custom_profile_field: {id: 3, value: "Value", rendered_value: "<p>Value</p>"},
|
|
|
|
});
|
2018-03-10 14:41:44 +01:00
|
|
|
person = people.get_by_email(me.email);
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(person.profile_data[3].value, "Value");
|
|
|
|
assert.equal(person.profile_data[3].rendered_value, "<p>Value</p>");
|
2018-08-02 08:54:28 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let updated = false;
|
2018-08-02 08:54:28 +02:00
|
|
|
settings_account.update_email = (email) => {
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(email, "you@example.org");
|
2018-08-02 08:54:28 +02:00
|
|
|
updated = true;
|
|
|
|
};
|
|
|
|
|
2022-01-05 18:08:47 +01:00
|
|
|
let confirm_banner_hidden = false;
|
|
|
|
settings_account.hide_confirm_email_banner = () => {
|
|
|
|
confirm_banner_hidden = true;
|
|
|
|
};
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
user_events.update_person({user_id: me.user_id, delivery_email: "you@example.org"});
|
2021-06-10 08:32:54 +02:00
|
|
|
assert.ok(updated);
|
2022-01-05 18:08:47 +01:00
|
|
|
assert.ok(confirm_banner_hidden);
|
2019-05-29 06:21:54 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const test_bot = {
|
2020-07-15 01:29:15 +02:00
|
|
|
email: "test-bot@example.com",
|
2019-05-29 06:21:54 +02:00
|
|
|
user_id: 35,
|
2020-07-15 01:29:15 +02:00
|
|
|
full_name: "Test Bot",
|
2019-05-29 06:21:54 +02:00
|
|
|
is_bot: true,
|
|
|
|
bot_owner_id: isaac.id,
|
|
|
|
};
|
2020-05-26 22:34:15 +02:00
|
|
|
people.add_active_user(test_bot);
|
2019-05-29 06:21:54 +02:00
|
|
|
|
|
|
|
user_events.update_person({user_id: test_bot.user_id, bot_owner_id: me.user_id});
|
|
|
|
person = people.get_by_email(test_bot.email);
|
|
|
|
assert.equal(person.bot_owner_id, me.user_id);
|
2023-10-30 12:50:40 +01:00
|
|
|
|
|
|
|
let user_removed_from_streams = false;
|
|
|
|
stream_events.remove_deactivated_user_from_all_streams = (user_id) => {
|
|
|
|
assert.equal(user_id, isaac.user_id);
|
|
|
|
user_removed_from_streams = true;
|
|
|
|
};
|
|
|
|
user_events.update_person({user_id: isaac.user_id, is_active: false});
|
|
|
|
assert.ok(!people.is_person_active(isaac.user_id));
|
|
|
|
assert.ok(user_removed_from_streams);
|
|
|
|
|
|
|
|
user_events.update_person({user_id: isaac.user_id, is_active: true});
|
|
|
|
assert.ok(people.is_person_active(isaac.user_id));
|
|
|
|
|
2023-12-14 23:51:33 +01:00
|
|
|
stream_events.remove_deactivated_user_from_all_streams = noop;
|
2023-10-30 12:50:40 +01:00
|
|
|
|
|
|
|
let bot_data_updated = false;
|
|
|
|
settings_users.update_bot_data = (user_id) => {
|
|
|
|
assert.equal(user_id, test_bot.user_id);
|
|
|
|
bot_data_updated = true;
|
|
|
|
};
|
|
|
|
user_events.update_person({user_id: test_bot.user_id, is_active: false});
|
|
|
|
assert.equal(bot_data_updated, true);
|
|
|
|
|
|
|
|
bot_data_updated = false;
|
|
|
|
user_events.update_person({user_id: test_bot.user_id, is_active: true});
|
|
|
|
assert.ok(bot_data_updated);
|
2018-05-15 12:40:07 +02:00
|
|
|
});
|