scheduled_messages: Handle scheduled messages to inaccessible users.

Inaccessible users are shown as "Unknown user" in the scheduled
messages list.
This commit is contained in:
Sahil Batra
2023-12-01 16:23:45 +05:30
committed by Tim Abbott
parent 0fb89e41f6
commit d67717c0d7
5 changed files with 27 additions and 12 deletions

View File

@@ -421,11 +421,7 @@ export function get_full_names_for_poll_option(user_ids: number[]): string {
}
export function get_display_full_name(user_id: number): string {
const person = maybe_get_user_by_id(user_id);
if (!person) {
blueslip.error("Unknown user id", {user_id});
return "?";
}
const person = get_user_by_id_assert_valid(user_id);
if (muted_users.is_user_muted(user_id)) {
if (should_add_guest_user_indicator(user_id)) {

View File

@@ -47,7 +47,10 @@ export function open_scheduled_message_in_compose(scheduled_msg, should_narrow_t
const recipient_emails = [];
if (scheduled_msg.to) {
for (const recipient_id of scheduled_msg.to) {
recipient_emails.push(people.get_by_user_id(recipient_id).email);
const recipient_user = people.get_by_user_id(recipient_id);
if (!recipient_user.is_inaccessible_user) {
recipient_emails.push(recipient_user.email);
}
}
}
compose_args = {

View File

@@ -222,16 +222,23 @@ test("errors", ({disallow_rewire}) => {
display_recipient: [{id: 92714}],
};
blueslip.expect("error", "Unknown user_id in maybe_get_user_by_id", 2);
blueslip.expect("error", "Unknown user id", 2); // From person.js
blueslip.expect("error", "Unknown user_id in maybe_get_user_by_id", 1);
blueslip.expect("error", "Unknown user id", 1); // From person.js
// Expect each to throw two blueslip errors
// One from message_store.js, one from person.js
const emails = message_store.get_pm_emails(message);
assert.equal(emails, "?");
const names = message_store.get_pm_full_names(message);
assert.equal(names, "?");
assert.throws(
() => {
message_store.get_pm_full_names(message);
},
{
name: "Error",
message: "Unknown user_id in get_by_user_id: 92714",
},
);
message = {
type: "stream",

View File

@@ -494,7 +494,7 @@ test_people("get_full_names_for_poll_option", () => {
assert.equal(names, "Me Myself, Isaac Newton");
});
test_people("get_display_full_names", () => {
test_people("get_display_full_names", ({override}) => {
people.initialize_current_user(me.user_id);
people.add_active_user(steven);
people.add_active_user(bob);
@@ -502,7 +502,7 @@ test_people("get_display_full_names", () => {
people.add_active_user(guest);
page_params.realm_enable_guest_user_indicator = true;
const user_ids = [me.user_id, steven.user_id, bob.user_id, charles.user_id, guest.user_id];
let user_ids = [me.user_id, steven.user_id, bob.user_id, charles.user_id, guest.user_id];
let names = people.get_display_full_names(user_ids);
// This doesn't do anything special for the current user. The caller has
@@ -545,6 +545,12 @@ test_people("get_display_full_names", () => {
"translated: Muted user",
"translated: Muted user (guest)",
]);
override(settings_data, "user_can_access_all_other_users", () => false);
const inaccessible_user_id = 99;
user_ids = [me.user_id, steven.user_id, inaccessible_user_id];
names = people.get_display_full_names(user_ids, true);
assert.deepEqual(names, ["Me Myself", "Steven", "translated: Unknown user"]);
});
test_people("my_custom_profile_data", () => {

View File

@@ -40,6 +40,9 @@ const sample_message = {
const channel = mock_esm("../src/channel");
const message_store = mock_esm("../src/message_store");
mock_esm("../src/settings_data", {
user_can_access_all_other_users: () => true,
});
const spectators = mock_esm("../src/spectators", {
login_to_access() {},
});