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:
@@ -255,8 +255,7 @@ class PostQueryBuilder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts(post_query, includes: nil)
|
def posts(post_query, relation = Post.unscoped, includes: nil)
|
||||||
relation = Post.all
|
|
||||||
relation = add_joins(post_query, relation)
|
relation = add_joins(post_query, relation)
|
||||||
relation = build_relation(post_query, relation)
|
relation = build_relation(post_query, relation)
|
||||||
|
|
||||||
|
|||||||
@@ -1390,7 +1390,8 @@ class Post < ApplicationRecord
|
|||||||
def user_tag_match(query, user = CurrentUser.user, tag_limit: user.tag_query_limit, safe_mode: CurrentUser.safe_mode?)
|
def user_tag_match(query, user = CurrentUser.user, tag_limit: user.tag_query_limit, safe_mode: CurrentUser.safe_mode?)
|
||||||
post_query = PostQuery.normalize(query, current_user: user, tag_limit: tag_limit, safe_mode: safe_mode)
|
post_query = PostQuery.normalize(query, current_user: user, tag_limit: tag_limit, safe_mode: safe_mode)
|
||||||
post_query.validate_tag_limit!
|
post_query.validate_tag_limit!
|
||||||
post_query.with_implicit_metatags.posts
|
posts = post_query.with_implicit_metatags.posts
|
||||||
|
merge(posts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def search(params, current_user)
|
def search(params, current_user)
|
||||||
@@ -1408,7 +1409,7 @@ class Post < ApplicationRecord
|
|||||||
)
|
)
|
||||||
|
|
||||||
if params[:tags].present?
|
if params[:tags].present?
|
||||||
q = q.user_tag_match(params[:tags])
|
q = q.user_tag_match(params[:tags], current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:order].present?
|
if params[:order].present?
|
||||||
|
|||||||
@@ -5,21 +5,25 @@ class ModqueueControllerTest < ActionDispatch::IntegrationTest
|
|||||||
setup do
|
setup do
|
||||||
@admin = create(:admin_user)
|
@admin = create(:admin_user)
|
||||||
@user = create(:user)
|
@user = create(:user)
|
||||||
@post = create(:post, is_pending: true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "index action" do
|
context "index action" do
|
||||||
should "render" do
|
should "render" do
|
||||||
|
create(:post, is_pending: true)
|
||||||
get_auth modqueue_index_path, @admin
|
get_auth modqueue_index_path, @admin
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "render for a json response" do
|
should "render for a json response" do
|
||||||
|
create(:post, is_pending: true)
|
||||||
get_auth modqueue_index_path, @admin, as: :json
|
get_auth modqueue_index_path, @admin, as: :json
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
should "support the only= URL param" do
|
should "support the only= URL param" do
|
||||||
|
@post = create(:post, is_pending: true)
|
||||||
get_auth modqueue_index_path(only: "rating"), @admin, as: :json
|
get_auth modqueue_index_path(only: "rating"), @admin, as: :json
|
||||||
|
|
||||||
assert_response :success
|
assert_response :success
|
||||||
@@ -37,6 +41,23 @@ class ModqueueControllerTest < ActionDispatch::IntegrationTest
|
|||||||
assert_equal([post1.id, post2.id, post3.id], response.parsed_body.pluck("id"))
|
assert_equal([post1.id, post2.id, post3.id], response.parsed_body.pluck("id"))
|
||||||
end
|
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
|
should "include appealed posts in the modqueue" do
|
||||||
@appeal = create(:post_appeal)
|
@appeal = create(:post_appeal)
|
||||||
get_auth modqueue_index_path, @admin
|
get_auth modqueue_index_path, @admin
|
||||||
|
|||||||
@@ -1995,4 +1995,18 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_equal("https://www.example.com/data/original/77/d8/77d89bda37ea3af09158ed3282f8334f.gif", @post.file_url)
|
assert_equal("https://www.example.com/data/original/77/d8/77d89bda37ea3af09158ed3282f8334f.gif", @post.file_url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "Searching:" do
|
||||||
|
context "the user_tag_match method" do
|
||||||
|
should "should not negate conditions before the search" do
|
||||||
|
@post1 = create(:post, tag_string: "solo", is_pending: true)
|
||||||
|
@post2 = create(:post, tag_string: "touhou", is_deleted: true)
|
||||||
|
|
||||||
|
assert_equal([@post1.id], Post.pending.anon_tag_match("solo").pluck(:id))
|
||||||
|
assert_equal([], Post.pending.anon_tag_match("-solo").pluck(:id))
|
||||||
|
assert_equal([@post2.id], Post.deleted.anon_tag_match("touhou").pluck(:id))
|
||||||
|
assert_equal([], Post.deleted.anon_tag_match("-touhou").pluck(:id))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user