Fix #4053: Add disapproval index improvements.

Add search form to /moderator/post/disapprovals.
This commit is contained in:
evazion
2019-08-02 21:22:33 -05:00
parent 6c69165780
commit 39bd766b34
5 changed files with 89 additions and 8 deletions

View File

@@ -8,6 +8,7 @@ class PostDisapproval < ApplicationRecord
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
scope :with_message, -> {where("message is not null and message <> ''")}
scope :without_message, -> {where("message is null or message = ''")}
scope :breaks_rules, -> {where(:reason => "breaks_rules")}
scope :poor_quality, -> {where(:reason => "poor_quality")}
scope :disinterest, -> {where(:reason => ["disinterest", "legacy"])}
@@ -43,4 +44,37 @@ class PostDisapproval < ApplicationRecord
PostVote.create(:score => -1, :post_id => post_id)
end
end
concerning :SearchMethods do
class_methods do
def post_tags_match(query)
where(post_id: PostQueryBuilder.new(query).build.reorder(""))
end
def search(params)
q = super
q = q.attribute_matches(:post_id, params[:post_id])
q = q.attribute_matches(:user_id, params[:user_id])
q = q.attribute_matches(:message, params[:message_matches])
q = q.search_text_attribute(:message, params)
q = q.post_tags_match(params[:post_tags_match]) if params[:post_tags_match].present?
q = q.where(user_id: User.search(name_matches: params[:creator_name])) if params[:creator_name].present?
q = q.where(reason: params[:reason]) if params[:reason].present?
q = q.with_message if params[:has_message].to_s.truthy?
q = q.without_message if params[:has_message].to_s.falsy?
case params[:order]
when "post_id", "post_id_desc"
q = q.order(post_id: :desc, id: :desc)
else
q = q.apply_default_order(params)
end
q.apply_default_order(params)
end
end
end
end