Skip to content

A platform for community discussion. Free, open, simple.

FIX: use group name in unreachable mention warning (#34174)

David Battersby5dfa0f3cb666
diff --git a/plugins/chat/config/locales/server.en.yml b/plugins/chat/config/locales/server.en.yml
index 67a80b4d0d6..b479876579f 100644
--- a/plugins/chat/config/locales/server.en.yml
+++ b/plugins/chat/config/locales/server.en.yml
@@ -153,6 +153,7 @@ en:
mention_warning:
dismiss: "dismiss"
cannot_see: "%{first_identifier} can't access this channel and was not notified."
+ cannot_see_group: "Some members of %{group_name} can't access this channel and were not notified."
cannot_see_multiple:
one: "%{first_identifier} and %{count} other user cannot access this channel and were not notified."
other: "%{first_identifier} and %{count} other users cannot access this channel and were not notified."
diff --git a/plugins/chat/lib/chat/notifier.rb b/plugins/chat/lib/chat/notifier.rb
index 54f3f0cc3bc..2849e09b8d7 100644
--- a/plugins/chat/lib/chat/notifier.rb
+++ b/plugins/chat/lib/chat/notifier.rb
@@ -236,7 +236,12 @@ module Chat
end
# Notify when mentioned users are not able to access the channel
- publish_unreachable_mentions(inaccessible[:unreachable]) if inaccessible[:unreachable].any?
+ # When user does not have permission to see group members, use the group name instead
+ if show_group_warning(inaccessible[:unreachable])
+ publish_unreachable_group_warning(hidden_member_groups.first.name)
+ elsif inaccessible[:unreachable].any?
+ publish_unreachable_mentions(inaccessible[:unreachable])
+ end
# Notify when `@all` or `@here` is used when channel has global mentions disabled
publish_global_mentions_disabled if global_mentions_disabled
@@ -250,6 +255,16 @@ module Chat
publish_too_many_members_in_group_mention(too_many_members) if too_many_members.any?
end
+ def hidden_member_groups
+ @hidden_member_groups ||=
+ @parsed_mentions.groups_to_mention -
+ Group.where(id: @parsed_mentions.groups_to_mention.ids).members_visible_groups(@user)
+ end
+
+ def show_group_warning(users)
+ users.any? { |user| GroupUser.exists?(group: hidden_member_groups, user: user) }
+ end
+
def publish_inaccessible_mentions(users)
Chat::Publisher.publish_notice(
user_id: @user.id,
@@ -306,6 +321,19 @@ module Chat
)
end
+ def publish_unreachable_group_warning(group_name)
+ Chat::Publisher.publish_notice(
+ user_id: @user.id,
+ channel_id: @chat_channel.id,
+ text_content:
+ I18n.t(
+ "chat.mention_warning.cannot_see_group",
+ group_name: group_name,
+ locale: @user.effective_locale,
+ ),
+ )
+ end
+
def publish_too_many_members_in_group_mention(groups)
Chat::Publisher.publish_notice(
user_id: @user.id,
diff --git a/plugins/chat/spec/system/channel_notice_spec.rb b/plugins/chat/spec/system/channel_notice_spec.rb
index fbbaa621cb7..a289333a224 100644
--- a/plugins/chat/spec/system/channel_notice_spec.rb
+++ b/plugins/chat/spec/system/channel_notice_spec.rb
@@ -6,6 +6,8 @@ RSpec.describe "Channel notice", type: :system do
let(:drawer_page) { PageObjects::Pages::ChatDrawer.new }
fab!(:current_user, :user)
+ fab!(:user_1, :user)
+ fab!(:user_2, :user)
before do
chat_system_bootstrap
@@ -14,6 +16,22 @@ RSpec.describe "Channel notice", type: :system do
context "when mentioned user can't see the channel" do
fab!(:secret_group, :group)
+ fab!(:group_2) do
+ Fabricate(
+ :public_group,
+ mentionable_level: Group::ALIAS_LEVELS[:everyone],
+ members_visibility_level: 0, # everyone
+ users: [user_1],
+ )
+ end
+ fab!(:group_3) do
+ Fabricate(
+ :public_group,
+ mentionable_level: Group::ALIAS_LEVELS[:everyone],
+ members_visibility_level: 3, # staff
+ users: [user_2],
+ )
+ end
fab!(:private_category) { Fabricate(:private_category, group: secret_group) }
fab!(:private_channel) { Fabricate(:chat_channel, chatable: private_category) }
fab!(:mentioned_user, :user)
@@ -33,6 +51,28 @@ RSpec.describe "Channel notice", type: :system do
)
end
+ it "does not expose group members when member visibility is restricted" do
+ chat_page.visit_channel(private_channel)
+ channel_page.send_message("hello @#{group_2.name} and @#{group_3.name}")
+
+ expect(page).to have_selector(
+ ".chat-notices__notice",
+ text: I18n.t("chat.mention_warning.cannot_see_group", group_name: group_3.name),
+ )
+ end
+
+ it "does not show group notice if unreachable member is not part of member visibility restricted group" do
+ secret_group.add(user_2)
+
+ chat_page.visit_channel(private_channel)
+ channel_page.send_message("hello @#{group_2.name} and @#{group_3.name}")
+
+ expect(page).to have_no_selector(
+ ".chat-notices__notice",
+ text: I18n.t("chat.mention_warning.cannot_see_group", group_name: group_3.name),
+ )
+ end
+
context "when navigating away and back to the channel" do
it "dismisses the notice" do
chat_page.visit_channel(private_channel)