From 918c0b039b0534a71729a0e7e925f586d1093f94 Mon Sep 17 00:00:00 2001 From: yogesh sirsat Date: Sat, 23 Apr 2022 00:02:41 +0530 Subject: [PATCH] popovers: Hide "Send private message" if user not have PM permissions. If an organization does not allow to send private messages, it will not display the "Send private message" option in the profile popover. Currently, there are only two options in settings, first is to allow every type of user to send PMs and the second is to disable send PMs for everyone, hence I am just checking that the second option is not selected. Fixes: #21888 --- frontend_tests/node_tests/popovers.js | 1 + static/js/popovers.js | 9 ++++++++- static/templates/user_info_popover_content.hbs | 4 +--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js index 183d555fb1..a0e9c3c64a 100644 --- a/frontend_tests/node_tests/popovers.js +++ b/frontend_tests/node_tests/popovers.js @@ -176,6 +176,7 @@ test_ui("sender_hover", ({override, mock_template}) => { can_revoke_away: false, can_mute: true, can_manage_user: false, + can_send_private_message: true, can_unmute: false, user_full_name: "Alice Smith", user_email: "alice@example.com", diff --git a/static/js/popovers.js b/static/js/popovers.js index 05e55eb7c0..4ab5444f51 100644 --- a/static/js/popovers.js +++ b/static/js/popovers.js @@ -42,6 +42,7 @@ import * as realm_playground from "./realm_playground"; import * as reminder from "./reminder"; import * as resize from "./resize"; import * as rows from "./rows"; +import * as settings_config from "./settings_config"; import * as settings_data from "./settings_data"; import * as settings_users from "./settings_users"; import * as stream_popover from "./stream_popover"; @@ -205,6 +206,7 @@ function render_user_info_popover( } const muting_allowed = !is_me && !user.is_bot; + const is_active = people.is_active_user_for_popover(user.user_id); const is_muted = muted_users.is_user_muted(user.user_id); const status_text = user_status.get_status_text(user.user_id); const status_emoji_info = user_status.get_status_emoji(user.user_id); @@ -221,9 +223,14 @@ function render_user_info_popover( can_set_away, can_mute: muting_allowed && !is_muted, can_manage_user: page_params.is_admin && !is_me, + can_send_private_message: + is_active && + !is_me && + page_params.realm_private_message_policy !== + settings_config.private_message_policy_values.disabled.code, can_unmute: muting_allowed && is_muted, has_message_context, - is_active: people.is_active_user_for_popover(user.user_id), + is_active, is_bot: user.is_bot, is_me, is_sender_popover, diff --git a/static/templates/user_info_popover_content.hbs b/static/templates/user_info_popover_content.hbs index 9f9ed3befb..7d83222228 100644 --- a/static/templates/user_info_popover_content.hbs +++ b/static/templates/user_info_popover_content.hbs @@ -117,14 +117,12 @@ {{/if}} - {{#if is_active}} - {{#unless is_me}} + {{#if can_send_private_message}}
  • {{#tr}}Send private message{{/tr}} {{#if is_sender_popover}}(R){{/if}}
  • - {{/unless}} {{/if}} {{#unless is_me}}