Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
narrow-banner: Check private message policy for empty narrow title.
Lauryn Menardf06143bc7ce4
diff --git a/frontend_tests/node_tests/narrow.js b/frontend_tests/node_tests/narrow.jsindex 467e55aa497..a60a68f2b1d 100644--- a/frontend_tests/node_tests/narrow.js+++ b/frontend_tests/node_tests/narrow.js@@ -15,6 +15,7 @@ const people = zrequire("people");const stream_data = zrequire("stream_data");const {Filter} = zrequire("../js/filter");const narrow = zrequire("narrow");+const settings_config = zrequire("settings_config");const compose_pm_pill = mock_esm("../../static/js/compose_pm_pill");mock_esm("../../static/js/spectators", {@@ -296,6 +297,22 @@ run_test("show_empty_narrow_message", ({mock_template}) => {),);+ // organization has disabled sending private messages+ page_params.realm_private_message_policy =+ settings_config.private_message_policy_values.disabled.code;+ set_filter([["is", "private"]]);+ hide_all_empty_narrow_messages();+ narrow_banner.show_empty_narrow_message();+ assert.equal(+ $(".empty_feed_notice_main").html(),+ empty_narrow_html(+ "translated: You are not allowed to send private messages in this organization.",+ ),+ );++ // sending private messages enabled+ page_params.realm_private_message_policy =+ settings_config.private_message_policy_values.by_anyone.code;set_filter([["is", "private"]]);hide_all_empty_narrow_messages();narrow_banner.show_empty_narrow_message();@@ -323,6 +340,11 @@ run_test("show_empty_narrow_message", ({mock_template}) => {empty_narrow_html("translated: No topics are marked as resolved."),);+ // organization has disabled sending private messages+ page_params.realm_private_message_policy =+ settings_config.private_message_policy_values.disabled.code;++ // prioritize information about invalid user(s) in narrow/searchset_filter([["pm-with", ["Yo"]]]);hide_all_empty_narrow_messages();narrow_banner.show_empty_narrow_message();@@ -340,6 +362,19 @@ run_test("show_empty_narrow_message", ({mock_template}) => {empty_narrow_html("translated: One or more of these users do not exist!"),);+ set_filter([["pm-with", "[email protected]"]]);+ hide_all_empty_narrow_messages();+ narrow_banner.show_empty_narrow_message();+ assert.equal(+ $(".empty_feed_notice_main").html(),+ empty_narrow_html(+ "translated: You are not allowed to send private messages in this organization.",+ ),+ );++ // sending private messages enabled+ page_params.realm_private_message_policy =+ settings_config.private_message_policy_values.by_anyone.code;set_filter([["pm-with", "[email protected]"]]);hide_all_empty_narrow_messages();narrow_banner.show_empty_narrow_message();@@ -375,23 +410,41 @@ run_test("show_empty_narrow_message", ({mock_template}) => {),);+ // organization has disabled sending private messages+ page_params.realm_private_message_policy =+ settings_config.private_message_policy_values.disabled.code;++ // prioritize information about invalid user in narrow/search+ set_filter([["group-pm-with", ["Yo"]]]);+ hide_all_empty_narrow_messages();+ narrow_banner.show_empty_narrow_message();+ assert.equal(+ $(".empty_feed_notice_main").html(),+ empty_narrow_html("translated: This user does not exist!"),+ );+set_filter([["group-pm-with", "[email protected]"]]);hide_all_empty_narrow_messages();narrow_banner.show_empty_narrow_message();assert.equal($(".empty_feed_notice_main").html(),empty_narrow_html(- "translated: You have no group private messages with this person yet!",- 'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',+ "translated: You are not allowed to send group private messages in this organization.",),);- set_filter([["group-pm-with", ["Yo"]]]);+ // sending private messages enabled+ page_params.realm_private_message_policy =+ settings_config.private_message_policy_values.by_anyone.code;+ set_filter([["group-pm-with", "[email protected]"]]);hide_all_empty_narrow_messages();narrow_banner.show_empty_narrow_message();assert.equal($(".empty_feed_notice_main").html(),- empty_narrow_html("translated: This user does not exist!"),+ empty_narrow_html(+ "translated: You have no group private messages with this person yet!",+ 'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',+ ),);set_filter([["sender", "[email protected]"]]);diff --git a/static/js/narrow_banner.js b/static/js/narrow_banner.jsindex 48c2f848192..ad38bd42613 100644--- a/static/js/narrow_banner.js+++ b/static/js/narrow_banner.js@@ -5,6 +5,7 @@ import {narrow_error} from "./narrow_error";import * as narrow_state from "./narrow_state";import {page_params} from "./page_params";import * as people from "./people";+import * as settings_config from "./settings_config";import * as spectators from "./spectators";import * as stream_data from "./stream_data";@@ -186,6 +187,17 @@ function pick_empty_narrow_banner() {};case "private":// You have no private messages.+ if (+ page_params.realm_private_message_policy ===+ settings_config.private_message_policy_values.disabled.code+ ) {+ return {+ title: $t({+ defaultMessage:+ "You are not allowed to send private messages in this organization.",+ }),+ };+ }return {title: $t({defaultMessage: "You have no private messages yet!"}),html: $t_html(@@ -280,6 +292,17 @@ function pick_empty_narrow_banner() {title: $t({defaultMessage: "One or more of these users do not exist!"}),};}+ if (+ page_params.realm_private_message_policy ===+ settings_config.private_message_policy_values.disabled.code+ ) {+ return {+ title: $t({+ defaultMessage:+ "You are not allowed to send private messages in this organization.",+ }),+ };+ }if (!first_operand.includes(",")) {// You have no private messages with this personif (people.is_current_user(first_operand)) {@@ -345,26 +368,35 @@ function pick_empty_narrow_banner() {title: $t({defaultMessage: "This user does not exist!"}),};case "group-pm-with":- if (people.get_by_email(first_operand)) {+ if (!people.get_by_email(first_operand)) {+ return {+ title: $t({defaultMessage: "This user does not exist!"}),+ };+ }+ if (+ page_params.realm_private_message_policy ===+ settings_config.private_message_policy_values.disabled.code+ ) {return {title: $t({- defaultMessage: "You have no group private messages with this person yet!",+ defaultMessage:+ "You are not allowed to send group private messages in this organization.",}),- html: $t_html(- {- defaultMessage: "Why not <z-link>start the conversation</z-link>?",- },- {- "z-link": (content_html) =>- `<a href="#" class="empty_feed_compose_private">${content_html.join(- "",- )}</a>`,- },- ),};}return {- title: $t({defaultMessage: "This user does not exist!"}),+ title: $t({+ defaultMessage: "You have no group private messages with this person yet!",+ }),+ html: $t_html(+ {+ defaultMessage: "Why not <z-link>start the conversation</z-link>?",+ },+ {+ "z-link": (content_html) =>+ `<a href="#" class="empty_feed_compose_private">${content_html}</a>`,+ },+ ),};}return default_banner;