Fix #2344: Negating status metatag breaks deleted post filter.

This commit is contained in:
evazion
2017-07-28 18:27:31 -05:00
parent 4b635628cc
commit 1c38fbbf64
2 changed files with 22 additions and 1 deletions

View File

@@ -84,6 +84,14 @@ class PostQueryBuilder
relation
end
def hide_deleted_posts?(q)
return false if CurrentUser.admin_mode?
return false if !CurrentUser.user.hide_deleted_posts?
return false if q[:status].in?(%w[deleted active])
return false if q[:status_neg].in?(%w[deleted active])
return true
end
def build(relation = nil)
unless query_string.is_a?(Hash)
q = Tag.parse_query(query_string)
@@ -144,7 +152,9 @@ class PostQueryBuilder
relation = relation.where("posts.is_banned = FALSE")
elsif q[:status_neg] == "active"
relation = relation.where("posts.is_pending = TRUE OR posts.is_deleted = TRUE OR posts.is_banned = TRUE")
elsif CurrentUser.user.hide_deleted_posts? && !CurrentUser.admin_mode?
end
if hide_deleted_posts?(q)
relation = relation.where("posts.is_deleted = FALSE")
end

View File

@@ -1972,6 +1972,17 @@ class PostTest < ActiveSupport::TestCase
assert_tag_match(all - [flagged], "-status:active")
end
should "respect the 'Deleted post filter' option when using the status:banned metatag" do
deleted = FactoryGirl.create(:post, is_deleted: true, is_banned: true)
undeleted = FactoryGirl.create(:post, is_banned: true)
CurrentUser.hide_deleted_posts = true
assert_tag_match([undeleted], "status:banned")
CurrentUser.hide_deleted_posts = false
assert_tag_match([undeleted, deleted], "status:banned")
end
should "return posts for the filetype:<ext> metatag" do
png = FactoryGirl.create(:post, file_ext: "png")
jpg = FactoryGirl.create(:post, file_ext: "jpg")