mirror of https://github.com/zulip/zulip.git
narrow-banner: Check private message policy for empty narrow title.
For narrows that focus on private messages ("is:private", "pm-with", "group-pm-with"), we want to check the organization private message policy and set an empty narrow title that matches that policy. For these narrows with invalid users, we prioritize that message for the empty narrow title, instead of the private message policy message. Fixes #21889.
This commit is contained in:
parent
1fce1c3c73
commit
f06143bc7c
|
@ -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/search
|
||||
set_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", "alice@example.com"]]);
|
||||
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", "alice@example.com"]]);
|
||||
hide_all_empty_narrow_messages();
|
||||
narrow_banner.show_empty_narrow_message();
|
||||
|
@ -375,6 +410,32 @@ 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", "alice@example.com"]]);
|
||||
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 group 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([["group-pm-with", "alice@example.com"]]);
|
||||
hide_all_empty_narrow_messages();
|
||||
narrow_banner.show_empty_narrow_message();
|
||||
|
@ -386,14 +447,6 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
|||
),
|
||||
);
|
||||
|
||||
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([["sender", "ray@example.com"]]);
|
||||
hide_all_empty_narrow_messages();
|
||||
narrow_banner.show_empty_narrow_message();
|
||||
|
|
|
@ -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 person
|
||||
if (people.is_current_user(first_operand)) {
|
||||
|
@ -345,7 +368,22 @@ 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 are not allowed to send group private messages in this organization.",
|
||||
}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
title: $t({
|
||||
defaultMessage: "You have no group private messages with this person yet!",
|
||||
|
@ -356,17 +394,11 @@ function pick_empty_narrow_banner() {
|
|||
},
|
||||
{
|
||||
"z-link": (content_html) =>
|
||||
`<a href="#" class="empty_feed_compose_private">${content_html.join(
|
||||
"",
|
||||
)}</a>`,
|
||||
`<a href="#" class="empty_feed_compose_private">${content_html}</a>`,
|
||||
},
|
||||
),
|
||||
};
|
||||
}
|
||||
return {
|
||||
title: $t({defaultMessage: "This user does not exist!"}),
|
||||
};
|
||||
}
|
||||
return default_banner;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue