mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
compose: Show compose_error for deactivated users.
When a user tries to send a (group) private message to a deactivated user, a compose error is displayed. Fixes #13766. Co-authored-by: Signior-X <b19188@students.iitmandi.ac.in>
This commit is contained in:
committed by
Tim Abbott
parent
130f1d7153
commit
d1b18d2c07
@@ -48,6 +48,7 @@ const render_compose_private_stream_alert = mock_template("compose_private_strea
|
|||||||
|
|
||||||
const compose_closed_ui = zrequire("compose_closed_ui");
|
const compose_closed_ui = zrequire("compose_closed_ui");
|
||||||
const compose_fade = zrequire("compose_fade");
|
const compose_fade = zrequire("compose_fade");
|
||||||
|
const compose_pm_pill = zrequire("compose_pm_pill");
|
||||||
const compose_state = zrequire("compose_state");
|
const compose_state = zrequire("compose_state");
|
||||||
const compose = zrequire("compose");
|
const compose = zrequire("compose");
|
||||||
const echo = zrequire("echo");
|
const echo = zrequire("echo");
|
||||||
@@ -614,6 +615,7 @@ test_ui("finish", ({override}) => {
|
|||||||
$("#compose-textarea").val("foobarfoobar");
|
$("#compose-textarea").val("foobarfoobar");
|
||||||
compose_state.set_message_type("private");
|
compose_state.set_message_type("private");
|
||||||
override(compose_state, "private_message_recipient", () => "bob@example.com");
|
override(compose_state, "private_message_recipient", () => "bob@example.com");
|
||||||
|
override(compose_pm_pill, "get_user_ids", () => []);
|
||||||
|
|
||||||
let compose_finished_event_checked = false;
|
let compose_finished_event_checked = false;
|
||||||
$(document).on("compose_finished.zulip", () => {
|
$(document).on("compose_finished.zulip", () => {
|
||||||
|
|||||||
@@ -213,6 +213,13 @@ test_ui("validate", ({override}) => {
|
|||||||
compose_state.private_message_recipient("bob@example.com");
|
compose_state.private_message_recipient("bob@example.com");
|
||||||
assert.ok(compose.validate());
|
assert.ok(compose.validate());
|
||||||
|
|
||||||
|
people.deactivate(bob);
|
||||||
|
assert.ok(!compose.validate());
|
||||||
|
assert.equal(
|
||||||
|
$("#compose-error-msg").html(),
|
||||||
|
$t_html({defaultMessage: "You cannot send messages to deactivated users."}),
|
||||||
|
);
|
||||||
|
|
||||||
page_params.realm_is_zephyr_mirror_realm = true;
|
page_params.realm_is_zephyr_mirror_realm = true;
|
||||||
assert.ok(compose.validate());
|
assert.ok(compose.validate());
|
||||||
page_params.realm_is_zephyr_mirror_realm = false;
|
page_params.realm_is_zephyr_mirror_realm = false;
|
||||||
|
|||||||
@@ -716,10 +716,12 @@ function validate_stream_message() {
|
|||||||
// The function checks whether the recipients are users of the realm or cross realm users (bots
|
// The function checks whether the recipients are users of the realm or cross realm users (bots
|
||||||
// for now)
|
// for now)
|
||||||
function validate_private_message() {
|
function validate_private_message() {
|
||||||
if (page_params.realm_private_message_policy === 2) {
|
|
||||||
// Frontend check for for PRIVATE_MESSAGE_POLICY_DISABLED
|
|
||||||
const user_ids = compose_pm_pill.get_user_ids();
|
const user_ids = compose_pm_pill.get_user_ids();
|
||||||
if (user_ids.length !== 1 || !people.get_by_user_id(user_ids[0]).is_bot) {
|
|
||||||
|
if (
|
||||||
|
page_params.realm_private_message_policy === 2 && // Frontend check for for PRIVATE_MESSAGE_POLICY_DISABLED
|
||||||
|
(user_ids.length !== 1 || !people.get_by_user_id(user_ids[0]).is_bot)
|
||||||
|
) {
|
||||||
// Unless we're composing to a bot
|
// Unless we're composing to a bot
|
||||||
compose_error.show(
|
compose_error.show(
|
||||||
$t_html({defaultMessage: "Private messages are disabled in this organization."}),
|
$t_html({defaultMessage: "Private messages are disabled in this organization."}),
|
||||||
@@ -727,7 +729,6 @@ function validate_private_message() {
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (compose_state.private_message_recipient().length === 0) {
|
if (compose_state.private_message_recipient().length === 0) {
|
||||||
compose_error.show(
|
compose_error.show(
|
||||||
@@ -758,6 +759,22 @@ function validate_private_message() {
|
|||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const user_id of user_ids) {
|
||||||
|
if (!people.is_person_active(user_id)) {
|
||||||
|
context = {full_name: people.get_by_user_id(user_id).full_name};
|
||||||
|
compose_error.show(
|
||||||
|
$t_html(
|
||||||
|
{defaultMessage: "You cannot send messages to deactivated users."},
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
$("#private_message_recipient"),
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user