Fix #4053: Add disapproval index improvements.
Add search form to /moderator/post/disapprovals.
This commit is contained in:
@@ -3,7 +3,7 @@ module Moderator
|
|||||||
class DisapprovalsController < ApplicationController
|
class DisapprovalsController < ApplicationController
|
||||||
before_action :approver_only
|
before_action :approver_only
|
||||||
skip_before_action :api_check
|
skip_before_action :api_check
|
||||||
respond_to :js, :json, :xml
|
respond_to :js, :html, :json, :xml
|
||||||
|
|
||||||
def create
|
def create
|
||||||
cookies.permanent[:moderated] = Time.now.to_i
|
cookies.permanent[:moderated] = Time.now.to_i
|
||||||
@@ -12,7 +12,8 @@ module Moderator
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class PostDisapproval < ApplicationRecord
|
|||||||
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
|
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
|
||||||
|
|
||||||
scope :with_message, -> {where("message is not null and message <> ''")}
|
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 :breaks_rules, -> {where(:reason => "breaks_rules")}
|
||||||
scope :poor_quality, -> {where(:reason => "poor_quality")}
|
scope :poor_quality, -> {where(:reason => "poor_quality")}
|
||||||
scope :disinterest, -> {where(:reason => ["disinterest", "legacy"])}
|
scope :disinterest, -> {where(:reason => ["disinterest", "legacy"])}
|
||||||
@@ -43,4 +44,37 @@ class PostDisapproval < ApplicationRecord
|
|||||||
PostVote.create(:score => -1, :post_id => post_id)
|
PostVote.create(:score => -1, :post_id => post_id)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
@@ -2,20 +2,44 @@
|
|||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
<h1>Disapprovals</h1>
|
<h1>Disapprovals</h1>
|
||||||
|
|
||||||
<table class="striped" width="100%">
|
<%= simple_form_for(:search, url: moderator_post_disapprovals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||||
|
<%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name] } %>
|
||||||
|
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||||
|
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||||
|
<%= f.input :message_matches, label: "Message", input_html: { value: params[:search][:message_matches] } %>
|
||||||
|
<%= f.input :reason, label: "Reason", collection: %w[breaks_rules disinterest poor_quality].map { |x| [x.humanize, x] }, include_blank: true, selected: params[:search][:reason] %>
|
||||||
|
<%= f.input :has_message, label: "Has Message?", collection: %w[Yes No], include_blank: true, selected: params[:search][:has_message] %>
|
||||||
|
<%= f.input :order, collection: [["ID", "id_desc"], ["Post ID", "post_id_desc"]], selected: params[:search][:order] %>
|
||||||
|
<%= f.submit "Search" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<table class="striped autofit" width="100%">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Post</th>
|
<th>Post</th>
|
||||||
|
<th>Message</th>
|
||||||
<th>Reason</th>
|
<th>Reason</th>
|
||||||
<th>Creator</th>
|
<th>Created</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @post_disapprovals.each do |post_disapproval| %>
|
<% @post_disapprovals.each do |post_disapproval| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= link_to post_disapproval.post_id, post_path(post_disapproval.post_id) %></td>
|
<td>
|
||||||
<td><%= post_disapproval.reason %>: <%= post_disapproval.message %></td>
|
<%= link_to "post ##{post_disapproval.post_id}", post_path(post_disapproval.post_id) %>
|
||||||
<td><%= post_disapproval.user.name %></td>
|
<%= link_to "»", moderator_post_disapprovals_path(search: params[:search].merge(post_id: post_disapproval.post_id)) %>
|
||||||
|
</td>
|
||||||
|
<td class="col-expand"><%= format_text(post_disapproval.message) %></td>
|
||||||
|
<td>
|
||||||
|
<%= link_to post_disapproval.reason.humanize, moderator_post_disapprovals_path(search: params[:search].merge(reason: post_disapproval.reason)) %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= link_to_user post_disapproval.user %>
|
||||||
|
<%= link_to "»", moderator_post_disapprovals_path(search: params[:search].merge(creator_name: post_disapproval.user&.name)) %>
|
||||||
|
<p>
|
||||||
|
<%= compact_time(post_disapproval.updated_at) %>
|
||||||
|
</p>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ module Moderator
|
|||||||
as_user do
|
as_user do
|
||||||
@post = create(:post, :is_pending => true)
|
@post = create(:post, :is_pending => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
CurrentUser.user = @admin
|
||||||
end
|
end
|
||||||
|
|
||||||
context "create action" do
|
context "create action" do
|
||||||
@@ -28,6 +30,15 @@ module Moderator
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
should "render" do
|
||||||
|
disapproval = FactoryBot.create(:post_disapproval, post: @post)
|
||||||
|
get_auth moderator_post_disapprovals_path, @admin
|
||||||
|
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ require 'test_helper'
|
|||||||
class PostDisapprovalTest < ActiveSupport::TestCase
|
class PostDisapprovalTest < ActiveSupport::TestCase
|
||||||
context "In all cases" do
|
context "In all cases" do
|
||||||
setup do
|
setup do
|
||||||
@alice = FactoryBot.create(:moderator_user)
|
@alice = FactoryBot.create(:moderator_user, name: "alice")
|
||||||
CurrentUser.user = @alice
|
CurrentUser.user = @alice
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
end
|
end
|
||||||
@@ -90,6 +90,17 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
|||||||
assert(@uploaders[1].dmails.exists?(from: bot, to: @uploaders[1]))
|
assert(@uploaders[1].dmails.exists?(from: bot, to: @uploaders[1]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#search" do
|
||||||
|
should "work" do
|
||||||
|
disapproval1 = FactoryBot.create(:post_disapproval, user: @alice, post: @post_1, reason: "breaks_rules")
|
||||||
|
disapproval2 = FactoryBot.create(:post_disapproval, user: @alice, post: @post_2, reason: "poor_quality", message: "bad anatomy")
|
||||||
|
|
||||||
|
assert_equal([disapproval1.id], PostDisapproval.search(reason: "breaks_rules").pluck(:id))
|
||||||
|
assert_equal([disapproval2.id], PostDisapproval.search(message: "bad anatomy").pluck(:id))
|
||||||
|
assert_equal([disapproval2.id, disapproval1.id], PostDisapproval.search(creator_name: "alice").pluck(:id))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user