Merge pull request #3701 from evazion/fix-3579
Fix #3579: Add post approval index
This commit is contained in:
8
app/controllers/post_approvals_controller.rb
Normal file
8
app/controllers/post_approvals_controller.rb
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class PostApprovalsController < ApplicationController
|
||||||
|
respond_to :html, :xml, :json
|
||||||
|
|
||||||
|
def index
|
||||||
|
@post_approvals = PostApproval.includes(:post, :user).search(search_params).paginate(params[:page], limit: params[:limit])
|
||||||
|
respond_with(@post_approvals)
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -5,10 +5,6 @@ class PostApproval < ApplicationRecord
|
|||||||
validate :validate_approval
|
validate :validate_approval
|
||||||
after_create :approve_post
|
after_create :approve_post
|
||||||
|
|
||||||
def self.prune!
|
|
||||||
where("created_at < ?", 1.month.ago).delete_all
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_approval
|
def validate_approval
|
||||||
if post.is_status_locked?
|
if post.is_status_locked?
|
||||||
errors.add(:post, "is locked and cannot be approved")
|
errors.add(:post, "is locked and cannot be approved")
|
||||||
@@ -33,4 +29,26 @@ class PostApproval < ApplicationRecord
|
|||||||
post.flags.each(&:resolve!)
|
post.flags.each(&:resolve!)
|
||||||
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
|
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
concerning :SearchMethods do
|
||||||
|
class_methods do
|
||||||
|
def post_tags_match(query)
|
||||||
|
PostQueryBuilder.new(query).build(self.joins(:post))
|
||||||
|
end
|
||||||
|
|
||||||
|
def search(params)
|
||||||
|
q = super
|
||||||
|
params[:user_id] = User.name_to_id(params[:user_name]) if params[:user_name]
|
||||||
|
|
||||||
|
if params[:post_tags_match].present?
|
||||||
|
q = q.post_tags_match(params[:post_tags_match])
|
||||||
|
end
|
||||||
|
|
||||||
|
q = q.attribute_matches(:user_id, params[:user_id])
|
||||||
|
q = q.attribute_matches(:post_id, params[:post_id])
|
||||||
|
|
||||||
|
q.apply_default_order(params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ class PostEvent
|
|||||||
include ActiveModel::Serializers::Xml
|
include ActiveModel::Serializers::Xml
|
||||||
|
|
||||||
attr_accessor :event
|
attr_accessor :event
|
||||||
delegate :creator, :creator_id, :reason, :is_resolved, :created_at, to: :event
|
delegate :created_at, to: :event
|
||||||
|
|
||||||
def self.find_for_post(post_id)
|
def self.find_for_post(post_id)
|
||||||
post = Post.find(post_id)
|
post = Post.find(post_id)
|
||||||
(post.appeals + post.flags).sort_by(&:created_at).reverse.map { |e| new(event: e) }
|
(post.appeals + post.flags + post.approvals).sort_by(&:created_at).reverse.map { |e| new(event: e) }
|
||||||
end
|
end
|
||||||
|
|
||||||
def type_name
|
def type_name
|
||||||
@@ -17,6 +17,8 @@ class PostEvent
|
|||||||
"flag"
|
"flag"
|
||||||
when PostAppeal
|
when PostAppeal
|
||||||
"appeal"
|
"appeal"
|
||||||
|
when PostApproval
|
||||||
|
"approval"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -24,9 +26,25 @@ class PostEvent
|
|||||||
type_name.first
|
type_name.first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reason
|
||||||
|
event.try(:reason) || ""
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_resolved
|
||||||
|
event.try(:is_resolved) || false
|
||||||
|
end
|
||||||
|
|
||||||
|
def creator_id
|
||||||
|
event.try(:creator_id) || event.try(:user_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def creator
|
||||||
|
event.try(:creator) || event.try(:user)
|
||||||
|
end
|
||||||
|
|
||||||
def is_creator_visible?(user = CurrentUser.user)
|
def is_creator_visible?(user = CurrentUser.user)
|
||||||
case event
|
case event
|
||||||
when PostAppeal
|
when PostAppeal, PostApproval
|
||||||
true
|
true
|
||||||
when PostFlag
|
when PostFlag
|
||||||
flag = event
|
flag = event
|
||||||
|
|||||||
42
app/views/post_approvals/index.html.erb
Normal file
42
app/views/post_approvals/index.html.erb
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<div id="c-post-approvals">
|
||||||
|
<div id="a-index">
|
||||||
|
<h1>Approvals</h1>
|
||||||
|
<%= render "posts/partials/common/inline_blacklist" %>
|
||||||
|
|
||||||
|
<%= simple_form_for(:search, url: post_approvals_path, method: :get, defaults: { required: false }, html: { class: "inline-form" }) do |f| %>
|
||||||
|
<%= f.input :user_name, label: "Approver", input_html: { value: params[:search][:user_name] } %>
|
||||||
|
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||||
|
<%= f.submit "Search" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<table width="100%" class="striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th width="1%">Post</th>
|
||||||
|
<th width="15%">Approver</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @post_approvals.each do |post_approval| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<%= PostPresenter.preview(post_approval.post, :tags => "status:any") %>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td>
|
||||||
|
<%= link_to_user post_approval.user %>
|
||||||
|
<%= link_to "»", post_approvals_path(search: params[:search].merge(user_name: post_approval.user.name)) %>
|
||||||
|
<br><%= time_ago_in_words_tagged post_approval.created_at %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<%= numbered_paginator(@post_approvals) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Approvals - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
<div id="c-post-events">
|
<div id="c-post-events">
|
||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
<h1>Flags & Appeals</h1>
|
<h1>Post Events</h1>
|
||||||
|
|
||||||
<table width="100%" class="striped">
|
<table width="100%" class="striped autofit">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="5%">Type</th>
|
<th>Type</th>
|
||||||
<th width="10%">Creator</th>
|
<th>User</th>
|
||||||
<th>Reason</th>
|
<th>Description</th>
|
||||||
<th width="5%">Resolved?</th>
|
<th>Resolved?</th>
|
||||||
<th width="15%">Date</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -22,16 +21,10 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<i>hidden</i>
|
<i>hidden</i>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<br><%= time_ago_in_words_tagged event.created_at %>
|
||||||
</td>
|
</td>
|
||||||
<td><%= format_text event.reason %></td>
|
<td class="col-expand"><%= format_text event.reason %></td>
|
||||||
<td>
|
<td><%= event.is_resolved %></td>
|
||||||
<% if event.is_resolved %>
|
|
||||||
yes
|
|
||||||
<% else %>
|
|
||||||
no
|
|
||||||
<% end %>
|
|
||||||
</td>
|
|
||||||
<td><%= compact_time event.created_at %></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -6,12 +6,8 @@
|
|||||||
<li><h1>Posts</h1></li>
|
<li><h1>Posts</h1></li>
|
||||||
<li><%= link_to("Help", wiki_pages_path(:title => "help:posts")) %></li>
|
<li><%= link_to("Help", wiki_pages_path(:title => "help:posts")) %></li>
|
||||||
<li><%= link_to("Listing", posts_path) %></li>
|
<li><%= link_to("Listing", posts_path) %></li>
|
||||||
<li><%= link_to("Changes", post_versions_path) %></li>
|
|
||||||
<li><%= link_to("Upload", new_upload_path) %></li>
|
<li><%= link_to("Upload", new_upload_path) %></li>
|
||||||
<li><%= link_to("Upload Listing", uploads_path) %></li>
|
<li><%= link_to("Upload Listing", uploads_path) %></li>
|
||||||
<li><%= link_to("Appeals", post_appeals_path) %></li>
|
|
||||||
<li><%= link_to("Flags", post_flags_path) %></li>
|
|
||||||
<li><%= link_to("Replacements", post_replacements_path) %></li>
|
|
||||||
<li><%= link_to("Popular", popular_explore_posts_path) %></li>
|
<li><%= link_to("Popular", popular_explore_posts_path) %></li>
|
||||||
<li><%= link_to("Most Viewed", viewed_explore_posts_path) %></li>
|
<li><%= link_to("Most Viewed", viewed_explore_posts_path) %></li>
|
||||||
<% if CurrentUser.can_approve_posts? %>
|
<% if CurrentUser.can_approve_posts? %>
|
||||||
@@ -21,6 +17,14 @@
|
|||||||
<li><%= link_to("Mass Edit", edit_moderator_tag_path) %></li>
|
<li><%= link_to("Mass Edit", edit_moderator_tag_path) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><h1>Post Events</h1></li>
|
||||||
|
<li><%= link_to("Changes", post_versions_path) %></li>
|
||||||
|
<li><%= link_to("Approvals", post_approvals_path) %></li>
|
||||||
|
<li><%= link_to("Appeals", post_appeals_path) %></li>
|
||||||
|
<li><%= link_to("Flags", post_flags_path) %></li>
|
||||||
|
<li><%= link_to("Replacements", post_replacements_path) %></li>
|
||||||
|
</ul>
|
||||||
<ul>
|
<ul>
|
||||||
<li><h1>Tools</h1></li>
|
<li><h1>Tools</h1></li>
|
||||||
<li><%= link_to("Source Code", Danbooru.config.source_code_url) %></li>
|
<li><%= link_to("Source Code", Danbooru.config.source_code_url) %></li>
|
||||||
|
|||||||
@@ -220,6 +220,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
resources :post_appeals
|
resources :post_appeals
|
||||||
resources :post_flags
|
resources :post_flags
|
||||||
|
resources :post_approvals, only: [:index]
|
||||||
resources :post_versions, :only => [:index, :search] do
|
resources :post_versions, :only => [:index, :search] do
|
||||||
member do
|
member do
|
||||||
put :undo
|
put :undo
|
||||||
|
|||||||
6
test/factories/post_approval.rb
Normal file
6
test/factories/post_approval.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
FactoryBot.define do
|
||||||
|
factory(:post_approval) do
|
||||||
|
user factory: :moderator_user
|
||||||
|
post factory: :post, is_pending: true
|
||||||
|
end
|
||||||
|
end
|
||||||
16
test/functional/post_approvals_controller_test.rb
Normal file
16
test/functional/post_approvals_controller_test.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class PostApprovalsControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
context "The post approvals controller" do
|
||||||
|
setup do
|
||||||
|
@approval = FactoryBot.create(:post_approval)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "index action" do
|
||||||
|
should "render" do
|
||||||
|
get post_approvals_path
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -9,8 +9,9 @@ class PostEventsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
as_user do
|
as_user do
|
||||||
@post = create(:post)
|
@post = create(:post)
|
||||||
@post_flag = PostFlag.create(:post => @post, :reason => "aaa", :is_resolved => false)
|
@post.flag!("aaa")
|
||||||
@post_appeal = PostAppeal.create(:post => @post, :reason => "aaa")
|
@post.appeal!("aaa")
|
||||||
|
@post.approve!(@mod)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class PostApprovalTest < ActiveSupport::TestCase
|
|||||||
CurrentUser.user = @user
|
CurrentUser.user = @user
|
||||||
CurrentUser.ip_addr = "127.0.0.1"
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
|
||||||
@post = FactoryBot.create(:post, uploader_id: @user.id, is_pending: true)
|
@post = FactoryBot.create(:post, uploader_id: @user.id, tag_string: "touhou", is_pending: true)
|
||||||
|
|
||||||
@approver = FactoryBot.create(:user)
|
@approver = FactoryBot.create(:user)
|
||||||
@approver.can_approve_posts = true
|
@approver.can_approve_posts = true
|
||||||
@@ -58,5 +58,14 @@ class PostApprovalTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#search method" do
|
||||||
|
should "work" do
|
||||||
|
@approval = @post.approve!(@approver)
|
||||||
|
@approvals = PostApproval.search(user_name: @approver.name, post_tags_match: "touhou", post_id: @post.id)
|
||||||
|
|
||||||
|
assert_equal([@approval.id], @approvals.map(&:id))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user