FIX: topic search wasn't working for unlisted topics

This commit is contained in:
Régis Hanol 2018-05-07 11:43:55 +02:00
parent 94163d7f1a
commit a98aae3bcd
2 changed files with 10 additions and 4 deletions

View File

@ -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)

View File

@ -251,7 +251,6 @@ describe Search do
end
it 'displays multiple results within a topic' do
topic = Fabricate(:topic)
topic2 = Fabricate(:topic)
@ -260,8 +259,7 @@ describe Search do
post1 = 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 do
results = 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)
end
end
context 'searching the OP' do