Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

scheduled_messages: Handle scheduled messages to inaccessible users.

Sahil Batrad67717c0d785
diff --git a/web/src/people.ts b/web/src/people.ts
index 4101a3d43e7..44d17fe61c5 100644
--- a/web/src/people.ts
+++ b/web/src/people.ts
@@ -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)) {
diff --git a/web/src/scheduled_messages_ui.js b/web/src/scheduled_messages_ui.js
index e92a5efc014..202bd80ce74 100644
--- a/web/src/scheduled_messages_ui.js
+++ b/web/src/scheduled_messages_ui.js
@@ -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 = {
diff --git a/web/tests/message_store.test.js b/web/tests/message_store.test.js
index 36cc759b163..ff1f382bdca 100644
--- a/web/tests/message_store.test.js
+++ b/web/tests/message_store.test.js
@@ -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",
diff --git a/web/tests/people.test.js b/web/tests/people.test.js
index 5dc17bf05a6..e37928dd406 100644
--- a/web/tests/people.test.js
+++ b/web/tests/people.test.js
@@ -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", () => {
diff --git a/web/tests/reactions.test.js b/web/tests/reactions.test.js
index 6ffa4d65eb8..b6f399ae5bb 100644
--- a/web/tests/reactions.test.js
+++ b/web/tests/reactions.test.js
@@ -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() {},
});