diff --git a/app/controllers/moderator/post/disapprovals_controller.rb b/app/controllers/moderator/post/disapprovals_controller.rb index e8838d60b..aef11f095 100644 --- a/app/controllers/moderator/post/disapprovals_controller.rb +++ b/app/controllers/moderator/post/disapprovals_controller.rb @@ -3,7 +3,7 @@ module Moderator class DisapprovalsController < ApplicationController before_action :approver_only skip_before_action :api_check - respond_to :js, :json, :xml + respond_to :js, :html, :json, :xml def create cookies.permanent[:moderated] = Time.now.to_i @@ -12,7 +12,8 @@ module Moderator end def index - @post_disapprovals = PostDisapproval.paginate(params[:page]) + @post_disapprovals = PostDisapproval.includes(:user).search(search_params).paginate(params[:page], limit: params[:limit]) + respond_with(@post_disapprovals) end private diff --git a/app/models/post_disapproval.rb b/app/models/post_disapproval.rb index 4141abd4e..d0060cb2f 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -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 diff --git a/app/views/moderator/post/disapprovals/index.html.erb b/app/views/moderator/post/disapprovals/index.html.erb index 3f240668a..c28f0fca7 100644 --- a/app/views/moderator/post/disapprovals/index.html.erb +++ b/app/views/moderator/post/disapprovals/index.html.erb @@ -2,20 +2,44 @@
| Post | +Message | Reason | -Creator | +Created | ||
|---|---|---|---|---|---|---|
| <%= link_to post_disapproval.post_id, post_path(post_disapproval.post_id) %> | -<%= post_disapproval.reason %>: <%= post_disapproval.message %> | -<%= post_disapproval.user.name %> | ++ <%= link_to "post ##{post_disapproval.post_id}", post_path(post_disapproval.post_id) %> + <%= link_to "»", moderator_post_disapprovals_path(search: params[:search].merge(post_id: post_disapproval.post_id)) %> + | +<%= format_text(post_disapproval.message) %> | ++ <%= link_to post_disapproval.reason.humanize, moderator_post_disapprovals_path(search: params[:search].merge(reason: post_disapproval.reason)) %> + | +
+ <%= link_to_user post_disapproval.user %>
+ <%= link_to "»", moderator_post_disapprovals_path(search: params[:search].merge(creator_name: post_disapproval.user&.name)) %>
+ + <%= compact_time(post_disapproval.updated_at) %> + + |