mirror of https://github.com/zulip/zulip.git
narrow-banner: Exclude bots when checking org sending pms policy.
Private messages between a user and a bot are not restricted by the organization's policy setting for sending private messages. So, for the empty banner text, we set the default title for a single bot for the "pm-with" narrow. Group private messages that include a bot are restricted by this policy setting, so those messages stay the same. Also, since bot's aren't people, we update the text for valid "pm-with", "sender" and "group-pm-with" operands to include the user's full name in the title. When there are multiple people in the "pm-with" narrow, we still send a generic "these people" message instead of listing all the users in the narrow. Finally, we make the default message end in a period instead of an exclamation mark.
This commit is contained in:
parent
f06143bc7c
commit
6b4ab21562
|
@ -57,6 +57,13 @@ const ray = {
|
||||||
full_name: "Raymond",
|
full_name: "Raymond",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const bot = {
|
||||||
|
email: "bot@example.com",
|
||||||
|
user_id: 25,
|
||||||
|
full_name: "Example Bot",
|
||||||
|
is_bot: true,
|
||||||
|
};
|
||||||
|
|
||||||
function hide_all_empty_narrow_messages() {
|
function hide_all_empty_narrow_messages() {
|
||||||
const all_empty_narrow_messages = [
|
const all_empty_narrow_messages = [
|
||||||
".empty_feed_notice",
|
".empty_feed_notice",
|
||||||
|
@ -372,6 +379,32 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// private messages with a bot are possible even though
|
||||||
|
// the organization has disabled sending private messages
|
||||||
|
people.add_active_user(bot);
|
||||||
|
set_filter([["pm-with", "bot@example.com"]]);
|
||||||
|
hide_all_empty_narrow_messages();
|
||||||
|
narrow_banner.show_empty_narrow_message();
|
||||||
|
assert.equal(
|
||||||
|
$(".empty_feed_notice_main").html(),
|
||||||
|
empty_narrow_html(
|
||||||
|
"translated HTML: You have no private messages with Example Bot yet.",
|
||||||
|
'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// group private messages with bots are not possible when
|
||||||
|
// sending private messages is disabled
|
||||||
|
set_filter([["pm-with", bot.email + "," + alice.email]]);
|
||||||
|
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
|
// sending private messages enabled
|
||||||
page_params.realm_private_message_policy =
|
page_params.realm_private_message_policy =
|
||||||
settings_config.private_message_policy_values.by_anyone.code;
|
settings_config.private_message_policy_values.by_anyone.code;
|
||||||
|
@ -381,7 +414,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
$(".empty_feed_notice_main").html(),
|
$(".empty_feed_notice_main").html(),
|
||||||
empty_narrow_html(
|
empty_narrow_html(
|
||||||
"translated: You have no private messages with this person yet!",
|
"translated HTML: You have no private messages with Alice Smith yet.",
|
||||||
'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',
|
'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -405,7 +438,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
$(".empty_feed_notice_main").html(),
|
$(".empty_feed_notice_main").html(),
|
||||||
empty_narrow_html(
|
empty_narrow_html(
|
||||||
"translated: You have no private messages with these people yet!",
|
"translated: You have no private messages with these people yet.",
|
||||||
'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',
|
'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -433,6 +466,18 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// group private messages with bots are not possible when
|
||||||
|
// sending private messages is disabled
|
||||||
|
set_filter([["group-pm-with", "bot@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
|
// sending private messages enabled
|
||||||
page_params.realm_private_message_policy =
|
page_params.realm_private_message_policy =
|
||||||
settings_config.private_message_policy_values.by_anyone.code;
|
settings_config.private_message_policy_values.by_anyone.code;
|
||||||
|
@ -442,7 +487,7 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
$(".empty_feed_notice_main").html(),
|
$(".empty_feed_notice_main").html(),
|
||||||
empty_narrow_html(
|
empty_narrow_html(
|
||||||
"translated: You have no group private messages with this person yet!",
|
"translated HTML: You have no group private messages with Alice Smith yet.",
|
||||||
'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',
|
'translated HTML: Why not <a href="#" class="empty_feed_compose_private">start the conversation</a>?',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -452,7 +497,9 @@ run_test("show_empty_narrow_message", ({mock_template}) => {
|
||||||
narrow_banner.show_empty_narrow_message();
|
narrow_banner.show_empty_narrow_message();
|
||||||
assert.equal(
|
assert.equal(
|
||||||
$(".empty_feed_notice_main").html(),
|
$(".empty_feed_notice_main").html(),
|
||||||
empty_narrow_html("translated: You haven't received any messages sent by this user yet!"),
|
empty_narrow_html(
|
||||||
|
"translated HTML: You haven't received any messages sent by Raymond yet.",
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
set_filter([["sender", "sinwar@example.com"]]);
|
set_filter([["sender", "sinwar@example.com"]]);
|
||||||
|
|
|
@ -152,7 +152,7 @@ async function search_silent_user(page: Page, str: string, item: string): Promis
|
||||||
await page.waitForSelector("#search_query", {visible: true});
|
await page.waitForSelector("#search_query", {visible: true});
|
||||||
await common.select_item_via_typeahead(page, "#search_query", str, item);
|
await common.select_item_via_typeahead(page, "#search_query", str, item);
|
||||||
await page.waitForSelector(".empty_feed_notice", {visible: true});
|
await page.waitForSelector(".empty_feed_notice", {visible: true});
|
||||||
const expect_message = "You haven't received any messages sent by this user yet!";
|
const expect_message = "You haven't received any messages sent by Email Gateway yet.";
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
await common.get_text_from_selector(page, ".empty_feed_notice"),
|
await common.get_text_from_selector(page, ".empty_feed_notice"),
|
||||||
expect_message,
|
expect_message,
|
||||||
|
|
|
@ -281,7 +281,7 @@ function pick_empty_narrow_banner() {
|
||||||
search_data: retrieve_search_query_data(),
|
search_data: retrieve_search_query_data(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case "pm-with":
|
case "pm-with": {
|
||||||
if (!people.is_valid_bulk_emails_for_compose(first_operand.split(","))) {
|
if (!people.is_valid_bulk_emails_for_compose(first_operand.split(","))) {
|
||||||
if (!first_operand.includes(",")) {
|
if (!first_operand.includes(",")) {
|
||||||
return {
|
return {
|
||||||
|
@ -292,9 +292,11 @@ function pick_empty_narrow_banner() {
|
||||||
title: $t({defaultMessage: "One or more of these users do not exist!"}),
|
title: $t({defaultMessage: "One or more of these users do not exist!"}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const user_ids = people.emails_strings_to_user_ids_array(first_operand);
|
||||||
if (
|
if (
|
||||||
page_params.realm_private_message_policy ===
|
page_params.realm_private_message_policy ===
|
||||||
settings_config.private_message_policy_values.disabled.code
|
settings_config.private_message_policy_values.disabled.code &&
|
||||||
|
(user_ids.length !== 1 || !people.get_by_user_id(user_ids[0]).is_bot)
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
title: $t({
|
title: $t({
|
||||||
|
@ -326,9 +328,12 @@ function pick_empty_narrow_banner() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
title: $t({
|
title: $t_html(
|
||||||
defaultMessage: "You have no private messages with this person yet!",
|
{
|
||||||
}),
|
defaultMessage: "You have no private messages with {person} yet.",
|
||||||
|
},
|
||||||
|
{person: people.get_by_user_id(user_ids[0]).full_name},
|
||||||
|
),
|
||||||
html: $t_html(
|
html: $t_html(
|
||||||
{
|
{
|
||||||
defaultMessage: "Why not <z-link>start the conversation</z-link>?",
|
defaultMessage: "Why not <z-link>start the conversation</z-link>?",
|
||||||
|
@ -343,7 +348,7 @@ function pick_empty_narrow_banner() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
title: $t({defaultMessage: "You have no private messages with these people yet!"}),
|
title: $t({defaultMessage: "You have no private messages with these people yet."}),
|
||||||
html: $t_html(
|
html: $t_html(
|
||||||
{
|
{
|
||||||
defaultMessage: "Why not <z-link>start the conversation</z-link>?",
|
defaultMessage: "Why not <z-link>start the conversation</z-link>?",
|
||||||
|
@ -356,19 +361,27 @@ function pick_empty_narrow_banner() {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
case "sender":
|
}
|
||||||
if (people.get_by_email(first_operand)) {
|
case "sender": {
|
||||||
|
const sender = people.get_by_email(first_operand);
|
||||||
|
if (sender) {
|
||||||
return {
|
return {
|
||||||
title: $t({
|
title: $t_html(
|
||||||
defaultMessage: "You haven't received any messages sent by this user yet!",
|
{
|
||||||
}),
|
defaultMessage:
|
||||||
|
"You haven't received any messages sent by {person} yet.",
|
||||||
|
},
|
||||||
|
{person: sender.full_name},
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
title: $t({defaultMessage: "This user does not exist!"}),
|
title: $t({defaultMessage: "This user does not exist!"}),
|
||||||
};
|
};
|
||||||
case "group-pm-with":
|
}
|
||||||
if (!people.get_by_email(first_operand)) {
|
case "group-pm-with": {
|
||||||
|
const person_in_group_pm = people.get_by_email(first_operand);
|
||||||
|
if (!person_in_group_pm) {
|
||||||
return {
|
return {
|
||||||
title: $t({defaultMessage: "This user does not exist!"}),
|
title: $t({defaultMessage: "This user does not exist!"}),
|
||||||
};
|
};
|
||||||
|
@ -385,9 +398,12 @@ function pick_empty_narrow_banner() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
title: $t({
|
title: $t_html(
|
||||||
defaultMessage: "You have no group private messages with this person yet!",
|
{
|
||||||
}),
|
defaultMessage: "You have no group private messages with {person} yet.",
|
||||||
|
},
|
||||||
|
{person: person_in_group_pm.full_name},
|
||||||
|
),
|
||||||
html: $t_html(
|
html: $t_html(
|
||||||
{
|
{
|
||||||
defaultMessage: "Why not <z-link>start the conversation</z-link>?",
|
defaultMessage: "Why not <z-link>start the conversation</z-link>?",
|
||||||
|
@ -399,6 +415,7 @@ function pick_empty_narrow_banner() {
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return default_banner;
|
return default_banner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue