Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Show `compose_error` for deactivated users.
Hashir Sarward1b18d2c0729
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex d089dda5049..f4656ea351c 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -48,6 +48,7 @@ const render_compose_private_stream_alert = mock_template("compose_private_streaconst compose_closed_ui = zrequire("compose_closed_ui");const compose_fade = zrequire("compose_fade");+const compose_pm_pill = zrequire("compose_pm_pill");const compose_state = zrequire("compose_state");const compose = zrequire("compose");const echo = zrequire("echo");@@ -614,6 +615,7 @@ test_ui("finish", ({override}) => {$("#compose-textarea").val("foobarfoobar");compose_state.set_message_type("private");override(compose_state, "private_message_recipient", () => "[email protected]");+ override(compose_pm_pill, "get_user_ids", () => []);let compose_finished_event_checked = false;$(document).on("compose_finished.zulip", () => {diff --git a/frontend_tests/node_tests/compose_validate.js b/frontend_tests/node_tests/compose_validate.jsindex 32f194e9874..6a1b790312c 100644--- a/frontend_tests/node_tests/compose_validate.js+++ b/frontend_tests/node_tests/compose_validate.js@@ -213,6 +213,13 @@ test_ui("validate", ({override}) => {compose_state.private_message_recipient("[email protected]");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;assert.ok(compose.validate());page_params.realm_is_zephyr_mirror_realm = false;diff --git a/static/js/compose.js b/static/js/compose.jsindex b74461c85f6..037328c55b0 100644--- a/static/js/compose.js+++ b/static/js/compose.js@@ -716,17 +716,18 @@ function validate_stream_message() {// The function checks whether the recipients are users of the realm or cross realm users (bots// for now)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();- if (user_ids.length !== 1 || !people.get_by_user_id(user_ids[0]).is_bot) {- // Unless we're composing to a bot- compose_error.show(- $t_html({defaultMessage: "Private messages are disabled in this organization."}),- $("#private_message_recipient"),- );- return false;- }+ const user_ids = compose_pm_pill.get_user_ids();++ 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+ compose_error.show(+ $t_html({defaultMessage: "Private messages are disabled in this organization."}),+ $("#private_message_recipient"),+ );+ return false;}if (compose_state.private_message_recipient().length === 0) {@@ -758,6 +759,22 @@ function validate_private_message() {);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;}