From 127378f0ec31958798d6466fd017b5a607d920d3 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Fri, 15 Sep 2023 23:30:56 +0530 Subject: [PATCH] users: Add "(guest)" to user name at various places. This commit adds code to get_display_full_name function to add "(guest)" indicator to guest user names if enable_guest_user_indicator setting is enabled in the organization. The get_display_full_name function is used in many parts of the code and thus this commit adds the indicator in following places - - Message recipient row for DMs including the messages shown in scheduled messages overlay. - DMs list in left sidebar and its tooltips. - DMs info recent conversations view. - "other senders" tooltip in recent conversations view. - Compose button text. - User names shown on reaction element and its tooltip. - Desktop notifications and the browser title. - Results for a poll. --- web/src/people.ts | 4 ++++ web/tests/people.test.js | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/web/src/people.ts b/web/src/people.ts index 0fbc78bf48..a50e33d8ab 100644 --- a/web/src/people.ts +++ b/web/src/people.ts @@ -424,6 +424,10 @@ export function get_display_full_name(user_id: number): string { return $t({defaultMessage: "Muted user"}); } + if (should_add_guest_user_indicator(user_id)) { + return $t({defaultMessage: "{name} (guest)"}, {name: person.full_name}); + } + return person.full_name; } diff --git a/web/tests/people.test.js b/web/tests/people.test.js index f3242bdb04..55a5344b22 100644 --- a/web/tests/people.test.js +++ b/web/tests/people.test.js @@ -470,16 +470,32 @@ test_people("get_display_full_names", () => { people.add_active_user(steven); people.add_active_user(bob); people.add_active_user(charles); - const user_ids = [me.user_id, steven.user_id, bob.user_id, charles.user_id]; + 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 names = people.get_display_full_names(user_ids); // This doesn't do anything special for the current user. The caller has // to take care of such cases and do the appropriate. - assert.deepEqual(names, ["Me Myself", "Steven", "Bob van Roberts", "Charles Dickens"]); + assert.deepEqual(names, [ + "Me Myself", + "Steven", + "Bob van Roberts", + "Charles Dickens", + "translated: Guest User (guest)", + ]); muted_users.add_muted_user(charles.user_id); + page_params.realm_enable_guest_user_indicator = false; names = people.get_display_full_names(user_ids); - assert.deepEqual(names, ["Me Myself", "Steven", "Bob van Roberts", "translated: Muted user"]); + assert.deepEqual(names, [ + "Me Myself", + "Steven", + "Bob van Roberts", + "translated: Muted user", + "Guest User", + ]); }); test_people("my_custom_profile_data", () => {