FIX: allow searching in PMs when "search this topic" is selected

This commit is contained in:
Sam 2015-02-19 12:56:49 +11:00
parent 67f404d281
commit 451788b95d
2 changed files with 11 additions and 2 deletions

View File

@ -294,7 +294,9 @@ class Search
.where("topics.deleted_at" => nil)
.where("topics.visible")
if opts[:private_messages]
is_topic_search = @search_context.present? && @search_context.is_a?(Topic)
if opts[:private_messages] || (is_topic_search && @search_context.private_message?)
posts = posts.where("topics.archetype = ?", Archetype.private_message)
unless @guardian.is_admin?
@ -304,7 +306,7 @@ class Search
posts = posts.where("topics.archetype <> ?", Archetype.private_message)
end
if @search_context.present? && @search_context.is_a?(Topic)
if is_topic_search
posts = posts.joins('JOIN users u ON u.id = posts.user_id')
posts = posts.where("posts.raw || ' ' || u.username || ' ' || u.name ilike ?", "%#{@term}%")
else

View File

@ -126,6 +126,13 @@ describe Search do
results.posts.length.should == 1
results = Search.execute('mars',
search_context: topic,
guardian: Guardian.new(reply.user))
results.posts.length.should == 1
# does not leak out
results = Search.execute('mars',
type_filter: 'private_messages',