Fix #4554: Searches with "-status:active" not showing deleted posts.
Also fixes #4542: Quoted search metatag status:"deleted" yields no results.
This commit is contained in:
@@ -59,6 +59,12 @@ module PostSets
|
|||||||
posts.any? {|x| x.rating == "e"}
|
posts.any? {|x| x.rating == "e"}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def shown_posts
|
||||||
|
shown_posts = posts.select(&:visible?)
|
||||||
|
shown_posts = shown_posts.reject(&:is_deleted?) unless show_deleted?
|
||||||
|
shown_posts
|
||||||
|
end
|
||||||
|
|
||||||
def hidden_posts
|
def hidden_posts
|
||||||
posts.reject(&:visible?)
|
posts.reject(&:visible?)
|
||||||
end
|
end
|
||||||
@@ -136,24 +142,22 @@ module PostSets
|
|||||||
|
|
||||||
def post_previews_html(template)
|
def post_previews_html(template)
|
||||||
html = ""
|
html = ""
|
||||||
if none_shown
|
if shown_posts.empty?
|
||||||
return template.render("post_sets/blank")
|
return template.render("post_sets/blank")
|
||||||
end
|
end
|
||||||
|
|
||||||
posts.each do |post|
|
shown_posts.each do |post|
|
||||||
html << PostPresenter.preview(post, show_cropped: true, tags: tag_string)
|
html << PostPresenter.preview(post, show_deleted: show_deleted?, show_cropped: true, tags: tag_string)
|
||||||
html << "\n"
|
html << "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
html.html_safe
|
html.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
def not_shown(post)
|
def show_deleted?
|
||||||
post.is_deleted? && tag_string !~ /status:(?:all|any|deleted|banned|modqueue)/
|
query.select_metatags("status").any? do |metatag|
|
||||||
end
|
metatag.value.in?(%w[all any active unmoderated modqueue deleted appealed])
|
||||||
|
end
|
||||||
def none_shown
|
|
||||||
posts.reject {|post| not_shown(post) }.empty?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
concerning :TagListMethods do
|
concerning :TagListMethods do
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ class PostPresenter
|
|||||||
attr_reader :pool, :next_post_in_pool
|
attr_reader :pool, :next_post_in_pool
|
||||||
delegate :tag_list_html, :split_tag_list_html, :split_tag_list_text, :inline_tag_list_html, to: :tag_set_presenter
|
delegate :tag_list_html, :split_tag_list_html, :split_tag_list_text, :inline_tag_list_html, to: :tag_set_presenter
|
||||||
|
|
||||||
def self.preview(post, options = {})
|
def self.preview(post, show_deleted: false, tags: "", **options)
|
||||||
if post.nil?
|
if post.nil?
|
||||||
return "<em>none</em>".html_safe
|
return "<em>none</em>".html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
if !options[:show_deleted] && post.is_deleted? && options[:tags] !~ /status:(?:all|any|deleted|banned|modqueue)/
|
if post.is_deleted? && !show_deleted
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -31,8 +31,8 @@ class PostPresenter
|
|||||||
locals[:link_target] = options[:link_target] || post
|
locals[:link_target] = options[:link_target] || post
|
||||||
|
|
||||||
locals[:link_params] = {}
|
locals[:link_params] = {}
|
||||||
if options[:tags].present? && !CurrentUser.is_anonymous?
|
if tags.present? && !CurrentUser.is_anonymous?
|
||||||
locals[:link_params]["q"] = options[:tags]
|
locals[:link_params]["q"] = tags
|
||||||
end
|
end
|
||||||
if options[:pool_id]
|
if options[:pool_id]
|
||||||
locals[:link_params]["pool_id"] = options[:pool_id]
|
locals[:link_params]["pool_id"] = options[:pool_id]
|
||||||
|
|||||||
@@ -361,6 +361,18 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_response :success
|
assert_response :success
|
||||||
assert_select "#post_#{@post.id}", 1
|
assert_select "#post_#{@post.id}", 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should 'show deleted posts when searching for status:"deleted"' do
|
||||||
|
get posts_path(tags: 'status:"deleted"')
|
||||||
|
assert_response :success
|
||||||
|
assert_select "#post_#{@post.id}", 1
|
||||||
|
end
|
||||||
|
|
||||||
|
should "show deleted posts when searching for -status:active" do
|
||||||
|
get posts_path(tags: "-status:active")
|
||||||
|
assert_response :success
|
||||||
|
assert_select "#post_#{@post.id}", 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with restricted posts" do
|
context "with restricted posts" do
|
||||||
|
|||||||
Reference in New Issue
Block a user