refactored post mod queue
This commit is contained in:
@@ -917,9 +917,10 @@ div#c-wiki-pages {
|
|||||||
|
|
||||||
|
|
||||||
/*** Post Moderation ***/
|
/*** Post Moderation ***/
|
||||||
div#c-post-moderation {
|
div#c-moderator-post-dashboards {
|
||||||
article {
|
article {
|
||||||
margin-bottom: 4em;
|
margin-bottom: 4em;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
aside {
|
aside {
|
||||||
|
|||||||
10
app/controllers/moderator/post/approvals_controller.rb
Normal file
10
app/controllers/moderator/post/approvals_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class ApprovalsController < ApplicationController
|
||||||
|
def create
|
||||||
|
@post = ::Post.find(params[:post_id])
|
||||||
|
@post.approve!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
13
app/controllers/moderator/post/dashboards_controller.rb
Normal file
13
app/controllers/moderator/post/dashboards_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class DashboardsController < ApplicationController
|
||||||
|
respond_to :html, :json
|
||||||
|
|
||||||
|
def show
|
||||||
|
@search = ::Post.order("id asc").pending_or_flagged.available_for_moderation.search(:tag_match => params[:query])
|
||||||
|
@posts = @search.paginate(params[:page])
|
||||||
|
respond_with(@posts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
15
app/controllers/moderator/post/disapprovals_controller.rb
Normal file
15
app/controllers/moderator/post/disapprovals_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class DisapprovalsController < ApplicationController
|
||||||
|
def create
|
||||||
|
@post = ::Post.find(params[:post_id])
|
||||||
|
@post_disapproval = PostDisapproval.create(:post => @post, :user => CurrentUser.user)
|
||||||
|
if @post_disapproval.errors.any?
|
||||||
|
raise ::Post::DisapprovalError.new(@post_disapproval.errors.full_messages)
|
||||||
|
end
|
||||||
|
|
||||||
|
# js: redirect to dashboard
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
15
app/controllers/moderator/post/posts_controller.rb
Normal file
15
app/controllers/moderator/post/posts_controller.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class PostsController < ApplicationController
|
||||||
|
def delete
|
||||||
|
@post = ::Post.find(params[:id])
|
||||||
|
@post.delete!
|
||||||
|
end
|
||||||
|
|
||||||
|
def undelete
|
||||||
|
@post = ::Post.find(params[:id])
|
||||||
|
@post.undelete!
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
class PostModerationController < ApplicationController
|
|
||||||
# before_filter :janitor_only
|
|
||||||
# rescue_from Post::ApprovalError, :with => :approval_error
|
|
||||||
# rescue_from Post::DisapprovalError, :with => :disapproval_error
|
|
||||||
|
|
||||||
def moderate
|
|
||||||
@search = Post.order("id asc").pending_or_flagged.available_for_moderation.search(:tag_match => params[:query])
|
|
||||||
@posts = @search.paginate(:page => params[:page])
|
|
||||||
respond_to do |format|
|
|
||||||
format.html
|
|
||||||
format.json {render :json => @posts.to_json}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def approve
|
|
||||||
@post = Post.find(params[:post_id])
|
|
||||||
@post.approve!
|
|
||||||
respond_to do |format|
|
|
||||||
format.html {redirect_to(post_moderation_moderate_path, :notice => "Post approved")}
|
|
||||||
format.js
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def disapprove
|
|
||||||
@post = Post.find(params[:post_id])
|
|
||||||
@post_disapproval = PostDisapproval.create(:post => @post, :user => CurrentUser.user)
|
|
||||||
if @post_disapproval.errors.any?
|
|
||||||
raise Post::DisapprovalError.new(@post_disapproval.errors.full_messages)
|
|
||||||
end
|
|
||||||
respond_to do |format|
|
|
||||||
format.html {redirect_to(post_moderation_moderate_path, :notice => "Post disapproved")}
|
|
||||||
format.js
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete
|
|
||||||
@post = Post.find(params[:post_id])
|
|
||||||
@post.delete!
|
|
||||||
end
|
|
||||||
|
|
||||||
def undelete
|
|
||||||
@post = Post.find(params[:post_id])
|
|
||||||
@post.undelete!
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
def disapproval_error(e)
|
|
||||||
respond_to do |format|
|
|
||||||
format.html {redirect_to(post_moderation_moderate_path, :notice => "You have already disapproved this post")}
|
|
||||||
format.js {render :action => "disapproval_error"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def approval_error(e)
|
|
||||||
respond_to do |format|
|
|
||||||
format.html {redirect_to(post_moderation_moderate_path, :notice => e.message)}
|
|
||||||
format.js {@exception = e; render :action => "approval_error"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -4,7 +4,7 @@ class PostDisapproval < ActiveRecord::Base
|
|||||||
validates_uniqueness_of :post_id, :scope => [:user_id]
|
validates_uniqueness_of :post_id, :scope => [:user_id]
|
||||||
|
|
||||||
def self.prune!
|
def self.prune!
|
||||||
joins(:post).where("posts.is_pending = FALSE AND posts.is_flagged = FALSE").select("post_disapprovals.*").each do |post_disapproval|
|
joins(:post).where("posts.is_pending = FALSE AND posts.is_flagged = FALSE").each do |post_disapproval|
|
||||||
post_disapproval.destroy
|
post_disapproval.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
1
app/views/moderator/post/approvals/create.js.erb
Normal file
1
app/views/moderator/post/approvals/create.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#post-<%= @post.id %>").remove();
|
||||||
40
app/views/moderator/post/dashboards/show.html.erb
Normal file
40
app/views/moderator/post/dashboards/show.html.erb
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<div id="c-moderator-post-dashboards">
|
||||||
|
<div id="a-show">
|
||||||
|
<div id="search">
|
||||||
|
<%= form_tag(moderator_post_dashboard_path, :method => :get) do %>
|
||||||
|
<%= text_field_tag "query", params[:query], :size => 40 %>
|
||||||
|
<%= submit_tag "Search" %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h1>Moderation Queue</h1>
|
||||||
|
|
||||||
|
<% @posts.each do |post| %>
|
||||||
|
<article id="post-<%= post.id %>">
|
||||||
|
<aside>
|
||||||
|
<%= link_to(image_tag(post.medium_file_url), post_path(post)) %>
|
||||||
|
</aside>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<ul>
|
||||||
|
<li><%= link_to "Approve", moderator_post_approval_path(:post_id => post.id), :remote => true, :method => :post %> | <%= link_to "Disapprove", moderator_post_disapproval_path(:post_id => post.id), :remote => true, :method => :post %></li>
|
||||||
|
<li>Rating: <%= post.rating %></li>
|
||||||
|
<li>Score: <%= post.score %></li>
|
||||||
|
<li>Uploader: <%= link_to(post.uploader.name, user_path(post.uploader_id)) %> <%= time_ago_in_words(post.created_at) %> ago</li>
|
||||||
|
<% if post.is_flagged? %>
|
||||||
|
<li>Flagged: <%= post_flag_reason(post) %></li>
|
||||||
|
<% end %>
|
||||||
|
<% if (post.is_flagged? || post.is_deleted?) && post.appeals.any? %>
|
||||||
|
<li>Appeals: <%= post_appeal_reason(post) %></li>
|
||||||
|
<% end %>
|
||||||
|
<li>Disapprovals: <%= post.disapprovals.count %></li>
|
||||||
|
<li>Tags: <%= post.tag_string %></li>
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
</article>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
1
app/views/moderator/post/disapprovals/create.js.erb
Normal file
1
app/views/moderator/post/disapprovals/create.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#post-<%= @post.id %>").remove();
|
||||||
1
app/views/moderator/post/posts/delete.js.erb
Normal file
1
app/views/moderator/post/posts/delete.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
$("#post-<%= @post.id %>").remove();
|
||||||
0
app/views/moderator/post/posts/undelete.js.erb
Normal file
0
app/views/moderator/post/posts/undelete.js.erb
Normal file
5
app/views/post_votes/create.js.erb
Normal file
5
app/views/post_votes/create.js.erb
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<% if @error %>
|
||||||
|
alert("<%= escape_javascript @error.to_s %>");
|
||||||
|
<% else %>
|
||||||
|
$("#score-for-post-<%= @post.id %> span").text(<%= @post.score %>);
|
||||||
|
<% end %>
|
||||||
@@ -9,6 +9,17 @@ Danbooru::Application.routes.draw do
|
|||||||
get :search
|
get :search
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
namespace :post do
|
||||||
|
resource :dashboard, :only => [:show]
|
||||||
|
resource :approval, :only => [:create]
|
||||||
|
resource :disapproval, :only => [:create]
|
||||||
|
resources :posts, :only => [:delete, :undelete] do
|
||||||
|
member do
|
||||||
|
post :delete
|
||||||
|
post :undelete
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
resources :advertisements do
|
resources :advertisements do
|
||||||
resources :hits, :controller => "advertisement_hits", :only => [:create]
|
resources :hits, :controller => "advertisement_hits", :only => [:create]
|
||||||
@@ -114,14 +125,6 @@ Danbooru::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :moderation do
|
|
||||||
namespace :post do
|
|
||||||
resource :dashboard, :only => [:show]
|
|
||||||
resource :approval, :only => [:destroy, :create]
|
|
||||||
resource :deletion, :only => [:destroy, :create]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
match "/site_map" => "static#site_map", :as => "site_map"
|
match "/site_map" => "static#site_map", :as => "site_map"
|
||||||
match "/terms_of_service" => "static#terms_of_service", :as => "terms_of_service"
|
match "/terms_of_service" => "static#terms_of_service", :as => "terms_of_service"
|
||||||
|
|
||||||
|
|||||||
26
test/functional/moderator/post/approvals_controller_test.rb
Normal file
26
test/functional/moderator/post/approvals_controller_test.rb
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class ApprovalsControllerTest < ActionController::TestCase
|
||||||
|
context "The moderator post approvals controller" do
|
||||||
|
setup do
|
||||||
|
@admin = Factory.create(:admin_user)
|
||||||
|
CurrentUser.user = @admin
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
|
||||||
|
@post = Factory.create(:post, :is_pending => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
should "render" do
|
||||||
|
post :create, {:post_id => @post.id, :format => "js"}, {:user_id => @admin.id}
|
||||||
|
assert_response :success
|
||||||
|
@post.reload
|
||||||
|
assert(!@post.is_pending?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
24
test/functional/moderator/post/dashboards_controller_test.rb
Normal file
24
test/functional/moderator/post/dashboards_controller_test.rb
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class DashboardsControllerTest < ActionController::TestCase
|
||||||
|
context "The moderator post dashboards controller" do
|
||||||
|
setup do
|
||||||
|
@admin = Factory.create(:admin_user)
|
||||||
|
CurrentUser.user = @admin
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
|
||||||
|
@post = Factory.create(:post, :is_pending => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "show action" do
|
||||||
|
should "render" do
|
||||||
|
get :show, {}, {:user_id => @admin.id}
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class DisapprovalsControllerTest < ActionController::TestCase
|
||||||
|
context "The moderator post disapprovals controller" do
|
||||||
|
setup do
|
||||||
|
@admin = Factory.create(:admin_user)
|
||||||
|
CurrentUser.user = @admin
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
|
||||||
|
@post = Factory.create(:post, :is_pending => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "create action" do
|
||||||
|
should "render" do
|
||||||
|
assert_difference("PostDisapproval.count", 1) do
|
||||||
|
post :create, {:post_id => @post.id, :format => "js"}, {:user_id => @admin.id}
|
||||||
|
end
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
41
test/functional/moderator/post/posts_controller_test.rb
Normal file
41
test/functional/moderator/post/posts_controller_test.rb
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
module Moderator
|
||||||
|
module Post
|
||||||
|
class PostsControllerTest < ActionController::TestCase
|
||||||
|
context "The moderator post disapprovals controller" do
|
||||||
|
setup do
|
||||||
|
@admin = Factory.create(:admin_user)
|
||||||
|
CurrentUser.user = @admin
|
||||||
|
CurrentUser.ip_addr = "127.0.0.1"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "delete action" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render" do
|
||||||
|
post :delete, {:id => @post.id, :format => "js"}, {:user_id => @admin.id}
|
||||||
|
assert_response :success
|
||||||
|
@post.reload
|
||||||
|
assert(@post.is_deleted?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "undelete action" do
|
||||||
|
setup do
|
||||||
|
@post = Factory.create(:post, :is_deleted => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render" do
|
||||||
|
post :undelete, {:id => @post.id, :format => "js"}, {:user_id => @admin.id}
|
||||||
|
assert_response :success
|
||||||
|
@post.reload
|
||||||
|
assert(!@post.is_deleted?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user