Fix #5132: Modqueue displays active posts when excluding any search term

Fix a bug where searching for a negated tag inside the modqueue would show
active posts.

The bug was that in a search like this:

    Post.in_modqueue.user_tag_match("-solo")

The `in_modqueue` condition would get sucked inside the tag search and negated
when we tried to apply the negation operator to the "solo" tag. So effectively
the `in_modqueue` condition would get negated and we would end up searching for
everything not in the modqueue.
This commit is contained in:
evazion
2022-09-28 00:13:39 -05:00
parent 59f166a637
commit 4c03ea5be3
4 changed files with 40 additions and 5 deletions

View File

@@ -5,21 +5,25 @@ class ModqueueControllerTest < ActionDispatch::IntegrationTest
setup do
@admin = create(:admin_user)
@user = create(:user)
@post = create(:post, is_pending: true)
end
context "index action" do
should "render" do
create(:post, is_pending: true)
get_auth modqueue_index_path, @admin
assert_response :success
end
should "render for a json response" do
create(:post, is_pending: true)
get_auth modqueue_index_path, @admin, as: :json
assert_response :success
end
should "support the only= URL param" do
@post = create(:post, is_pending: true)
get_auth modqueue_index_path(only: "rating"), @admin, as: :json
assert_response :success
@@ -37,6 +41,23 @@ class ModqueueControllerTest < ActionDispatch::IntegrationTest
assert_equal([post1.id, post2.id, post3.id], response.parsed_body.pluck("id"))
end
should "filter negated tags correctly" do
post1 = create(:post, tag_string: "touhou", is_pending: false)
post2 = create(:post, tag_string: "touhou", is_pending: true)
get_auth modqueue_index_path(search: { tags: "-solo" }), @admin, as: :json
assert_response :success
assert_equal([post2.id], response.parsed_body.pluck("id"))
get_auth modqueue_index_path(search: { tags: "touhou -solo" }), @admin, as: :json
assert_response :success
assert_equal([post2.id], response.parsed_body.pluck("id"))
get_auth modqueue_index_path(search: { tags: "-touhou" }), @admin, as: :json
assert_response :success
assert_equal([], response.parsed_body.pluck("id"))
end
should "include appealed posts in the modqueue" do
@appeal = create(:post_appeal)
get_auth modqueue_index_path, @admin