modqueue: fix the disapproved: metatag showing posts outside the queue.
Fix a bug where filtering the modqueue by the `disapproved:<reason>` tag would return posts outside the modqueue.
This commit is contained in:
@@ -9,6 +9,22 @@ module Searchable
|
||||
relation.where(all.where_clause.invert.ast)
|
||||
end
|
||||
|
||||
# Combine two relations like `ActiveRecord::Relation#and`, but allow structurally incompatible relations.
|
||||
def and_relation(relation)
|
||||
q = all
|
||||
raise "incompatible FROM clauses: #{q.to_sql}; #{relation.to_sql}" if !q.from_clause.empty? && q.from_clause != relation.from_clause
|
||||
raise "incompatible GROUP BY clauses: #{q.to_sql}; #{relation.to_sql}" if !q.group_values.empty? && q.group_values != relation.group_values
|
||||
|
||||
q = q.select(q.select_values + relation.select_values) if !relation.select_values.empty?
|
||||
q = q.from(relation.from_clause.value) if !relation.from_clause.empty?
|
||||
q = q.joins(relation.joins_values + q.joins_values) if relation.joins_values.present?
|
||||
q = q.where(relation.where_clause.ast) if relation.where_clause.present?
|
||||
q = q.group(relation.group_values) if relation.group_values.present?
|
||||
q = q.order(relation.order_values) if relation.order_values.present? && !relation.reordering_value
|
||||
q = q.reorder(relation.order_values) if relation.order_values.present? && relation.reordering_value
|
||||
q
|
||||
end
|
||||
|
||||
# Search a table column by an Arel operator.
|
||||
#
|
||||
# @see https://github.com/rails/rails/blob/master/activerecord/lib/arel/predications.rb
|
||||
|
||||
@@ -1391,7 +1391,7 @@ class Post < ApplicationRecord
|
||||
post_query = PostQuery.normalize(query, current_user: user, tag_limit: tag_limit, safe_mode: safe_mode)
|
||||
post_query.validate_tag_limit!
|
||||
posts = post_query.with_implicit_metatags.posts
|
||||
merge(posts)
|
||||
and_relation(posts)
|
||||
end
|
||||
|
||||
def search(params, current_user)
|
||||
@@ -1409,7 +1409,7 @@ class Post < ApplicationRecord
|
||||
)
|
||||
|
||||
if params[:tags].present?
|
||||
q = q.user_tag_match(params[:tags], current_user)
|
||||
q = q.where(id: user_tag_match(params[:tags], current_user).select(:id))
|
||||
end
|
||||
|
||||
if params[:order].present?
|
||||
|
||||
Reference in New Issue
Block a user