From 2ce9364c08c7dcfd00cca8929a1886732f33ab54 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 5 Jul 2023 21:12:39 +0200 Subject: [PATCH] FIX: do not filter on category name (#22442) --- .../chat/app/services/chat/search_chatable.rb | 10 ++++++---- plugins/chat/spec/system/new_message_spec.rb | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/chat/app/services/chat/search_chatable.rb b/plugins/chat/app/services/chat/search_chatable.rb index 84a1b58dbcf..6382d1b48b1 100644 --- a/plugins/chat/app/services/chat/search_chatable.rb +++ b/plugins/chat/app/services/chat/search_chatable.rb @@ -45,7 +45,7 @@ module Chat end def fetch_memberships(guardian:, **) - context.memberships = Chat::ChannelMembershipManager.all_for_user(guardian.user) + context.memberships = ::Chat::ChannelMembershipManager.all_for_user(guardian.user) end def fetch_users(guardian:, **) @@ -58,8 +58,10 @@ module Chat return if context.mode == :user context.category_channels = - Chat::ChannelFetcher.secured_public_channels( + ::Chat::ChannelFetcher.secured_public_channel_search( guardian, + filter_on_category_name: false, + match_filter_on_starts_with: false, filter: context.term, status: :open, limit: 10, @@ -76,7 +78,7 @@ module Chat end channels = - Chat::ChannelFetcher.secured_direct_message_channels_search( + ::Chat::ChannelFetcher.secured_direct_message_channels_search( guardian.user.id, guardian, limit: 10, @@ -97,7 +99,7 @@ module Chat end def search_users(term, guardian) - user_search = UserSearch.new(term, limit: 10) + user_search = ::UserSearch.new(term, limit: 10) if term.blank? user_search.scoped_users.includes(:user_option) diff --git a/plugins/chat/spec/system/new_message_spec.rb b/plugins/chat/spec/system/new_message_spec.rb index d9a90010ff8..8a1877a53f0 100644 --- a/plugins/chat/spec/system/new_message_spec.rb +++ b/plugins/chat/spec/system/new_message_spec.rb @@ -235,6 +235,22 @@ RSpec.describe "New message", type: :system do before { channel_1.add(current_user) } + context "when query is the name of the category" do + fab!(:category) { Fabricate(:category, name: "dev") } + fab!(:channel_1) { Fabricate(:category_channel, chatable: category, name: "something dev") } + fab!(:channel_2) { Fabricate(:category_channel, chatable: category, name: "something else") } + + it "favors the channel name" do + visit("/") + chat_page.open_new_message + + chat_page.message_creator.filter("dev") + + expect(chat_page.message_creator).to be_listing(channel_1) + expect(chat_page.message_creator).to be_not_listing(channel_2) + end + end + context "with no prefix" do it "lists all matching content" do visit("/")