post approvals: add index page + search options (fix #3579).

This commit is contained in:
evazion
2018-05-05 13:07:49 -05:00
parent 181a906766
commit 7c1d5e25fb
7 changed files with 105 additions and 5 deletions

View 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

View File

@@ -5,10 +5,6 @@ class PostApproval < ApplicationRecord
validate :validate_approval
after_create :approve_post
def self.prune!
where("created_at < ?", 1.month.ago).delete_all
end
def validate_approval
if post.is_status_locked?
errors.add(:post, "is locked and cannot be approved")
@@ -33,4 +29,26 @@ class PostApproval < ApplicationRecord
post.flags.each(&:resolve!)
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
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

View 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 %>