A platform for community discussion. Free, open, simple.
FIX: Do not return channels for hashtags if user cannot chat (#19417)
Martin Brennanf5b464ead583
diff --git a/plugins/chat/lib/chat_channel_hashtag_data_source.rb b/plugins/chat/lib/chat_channel_hashtag_data_source.rbindex 8073914b789..9540770c366 100644--- a/plugins/chat/lib/chat_channel_hashtag_data_source.rb+++ b/plugins/chat/lib/chat_channel_hashtag_data_source.rb@@ -18,6 +18,7 @@ class Chat::ChatChannelHashtagDataSourcedef self.lookup(guardian, slugs)if SiteSetting.enable_experimental_hashtag_autocomplete+ return [] if !guardian.can_chat?(guardian.user)Chat::ChatChannelFetcher.secured_public_channel_slug_lookup(guardian, slugs).map { |channel| channel_to_hashtag_item(guardian, channel) }@@ -28,6 +29,7 @@ class Chat::ChatChannelHashtagDataSourcedef self.search(guardian, term, limit)if SiteSetting.enable_experimental_hashtag_autocomplete+ return [] if !guardian.can_chat?(guardian.user)Chat::ChatChannelFetcher.secured_public_channel_search(guardian,@@ -47,6 +49,7 @@ class Chat::ChatChannelHashtagDataSourcedef self.search_without_term(guardian, limit)if SiteSetting.enable_experimental_hashtag_autocomplete+ return [] if !guardian.can_chat?(guardian.user)allowed_channel_ids_sql =Chat::ChatChannelFetcher.generate_allowed_channel_ids_sql(guardian,diff --git a/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rb b/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rbindex 5c7ca643a1d..30358123622 100644--- a/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rb+++ b/plugins/chat/spec/lib/chat_channel_hashtag_data_source_spec.rb@@ -26,7 +26,11 @@ RSpec.describe Chat::ChatChannelHashtagDataSource doendlet!(:guardian) { Guardian.new(user) }- before { SiteSetting.enable_experimental_hashtag_autocomplete = true }+ before do+ SiteSetting.enable_experimental_hashtag_autocomplete = true+ SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:trust_level_1]+ Group.refresh_automatic_groups!+ enddescribe "#lookup" doit "finds a channel by a slug" do@@ -67,6 +71,12 @@ RSpec.describe Chat::ChatChannelHashtagDataSource doresult = described_class.lookup(guardian, []).firstexpect(result).to eq(nil)end++ it "returns nothing if the user cannot chat" do+ SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff]+ Group.refresh_automatic_groups!+ expect(described_class.lookup(Guardian.new(user), ["random"])).to be_empty+ endenddescribe "#search" do@@ -123,6 +133,12 @@ RSpec.describe Chat::ChatChannelHashtagDataSource do},)end++ it "returns nothing if the user cannot chat" do+ SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff]+ Group.refresh_automatic_groups!+ expect(described_class.search(Guardian.new(user), "rand", 10)).to be_empty+ endenddescribe "#search_without_term" do@@ -160,5 +176,11 @@ RSpec.describe Chat::ChatChannelHashtagDataSource domembership3.update!(following: false)expect(described_class.search_without_term(guardian, 5).map(&:slug)).to eq(%w[chat random])end++ it "returns nothing if the user cannot chat" do+ SiteSetting.chat_allowed_groups = Group::AUTO_GROUPS[:staff]+ Group.refresh_automatic_groups!+ expect(described_class.search_without_term(Guardian.new(user), 10)).to be_empty+ endendend