Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
markdown: Do not show mention pills for inaccessible users.
Sahil Batra75ceba660022
diff --git a/web/src/people.ts b/web/src/people.tsindex 6016d69f4b6..733937957f8 100644--- a/web/src/people.ts+++ b/web/src/people.ts@@ -247,7 +247,17 @@ export function is_known_user_id(user_id: number): boolean {the mention syntax by manually typing it instead ofselecting some user from typeahead.*/- return people_by_user_id_dict.has(user_id);++ /*+ This function also returns false for inaccessible users+ even though we have the user_id for them as we do not+ want to show the mention pill for them.+ */+ const person = maybe_get_user_by_id(user_id, true);+ if (person === undefined || person.is_inaccessible_user) {+ return false;+ }+ return true;}export function is_known_user(user: User): boolean {@@ -1242,9 +1252,19 @@ export function filter_people_by_search_terms(}export const is_valid_full_name_and_user_id = (full_name: string, user_id: number): boolean => {+ /*+ This function is currently only used for checking+ the mention syntax during markdown parsing. Since+ we do not want to parse inaccessible users as+ mention pill, this function returns false for+ inaccessible users. We would need to update this+ if we would want to use this function for other+ cases where we might want to display inaccessible+ users as "Unknown user".+ */const person = people_by_user_id_dict.get(user_id);- if (!person) {+ if (!person || person.is_inaccessible_user) {return false;}@@ -1283,9 +1303,18 @@ export function get_user_id_from_name(full_name: string): number | undefined {exactly what we do with mentions.*/+ /*+ Since we do not want to parse inaccessible users as+ mention pill, this function returns false for+ inaccessible users. We would need to update this if+ we would want to use this function for other cases+ where we might want to display inaccessible users+ as "Unknown user".+ */+const person = people_by_name_dict.get(full_name);- if (!person) {+ if (!person || person.is_inaccessible_user) {return undefined;}diff --git a/web/tests/markdown.test.js b/web/tests/markdown.test.jsindex 50513127ae4..e037453dfa4 100644--- a/web/tests/markdown.test.js+++ b/web/tests/markdown.test.js@@ -5,7 +5,7 @@ const {strict: assert} = require("assert");const markdown_test_cases = require("../../zerver/tests/fixtures/markdown_test_cases");const markdown_assert = require("./lib/markdown_assert");-const {set_global, zrequire} = require("./lib/namespace");+const {mock_esm, set_global, zrequire} = require("./lib/namespace");const {run_test} = require("./lib/test");const {page_params, user_settings} = require("./lib/zpage_params");@@ -42,6 +42,10 @@ user_settings.translate_emoticons = false;set_global("document", {compatMode: "CSS1Compat"});+mock_esm("../src/settings_data", {+ user_can_access_all_other_users: () => false,+});+const emoji = zrequire("emoji");const emoji_codes = zrequire("../../static/generated/emoji/emoji_codes.json");const linkifiers = zrequire("linkifiers");@@ -111,6 +115,8 @@ people.add_active_user({email: "[email protected]",});+people.add_inaccessible_user(108);+people.initialize_current_user(cordelia.user_id);const hamletcharacters = {@@ -519,6 +525,14 @@ test("marked", () => {input: "@**|123|106** comes under user|id case.",expected: "<p>@**|123|106** comes under user|id case.</p>",},+ {+ input: "@**|108** mention inaccessible user using ID.",+ expected: "<p>@**|108** mention inaccessible user using ID.</p>",+ },+ {+ input: "@**Unknown user|108** mention inaccessible user using name and ID.",+ expected: "<p>@**Unknown user|108** mention inaccessible user using name and ID.</p>",+ },{input: "@**|1234** invalid id.", expected: "<p>@**|1234** invalid id.</p>"},{input: "T\n@hamletcharacters", expected: "<p>T<br>\n@hamletcharacters</p>"},{