A platform for community discussion. Free, open, simple.
FIX: topic search wasn't working for unlisted topics
Régis Hanola98aae3bcd5d
diff --git a/lib/search.rb b/lib/search.rbindex a61a36eb0f2..236ba6c96eb 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -660,10 +660,11 @@ class Search.joins(:post_search_data, :topic).joins("LEFT JOIN categories ON categories.id = topics.category_id").where("topics.deleted_at" => nil)- .where("topics.visible")is_topic_search = @search_context.present? && @search_context.is_a?(Topic)+ posts = posts.where("topics.visible") unless is_topic_search+if opts[:private_messages] || (is_topic_search && @search_context.private_message?)posts = posts.where("topics.archetype = ?", Archetype.private_message)diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rbindex 1e5c1a723e7..148f28be8b9 100644--- a/spec/components/search_spec.rb+++ b/spec/components/search_spec.rb@@ -251,7 +251,6 @@ describe Search doendit 'displays multiple results within a topic' do-topic = Fabricate(:topic)topic2 = Fabricate(:topic)@@ -260,8 +259,7 @@ describe Search dopost1 = new_post('this is the other post I am posting', topic)post2 = new_post('this is my first post I am posting', topic)- post3 = new_post('this is a real long and complicated bla this is my second post I am Posting birds- with more stuff bla bla', topic)+ post3 = new_post('this is a real long and complicated bla this is my second post I am Posting birds with more stuff bla bla', topic)post4 = new_post('this is my fourth post I am posting', topic)# update posts_count@@ -281,6 +279,13 @@ describe Search doresults = Search.execute('"fourth post I am posting"', search_context: post1.topic)expect(results.posts.length).to eq(1)end++ it "works for unlisted topics" do+ topic.update_attributes(visible: false)+ post = new_post('discourse is awesome', topic)+ results = Search.execute('discourse', search_context: topic)+ expect(results.posts.length).to eq(1)+ endendcontext 'searching the OP' do