Allow post disapprovals to be edited
This commit is contained in:
@@ -17,4 +17,17 @@ class PostDisapprovalsController < ApplicationController
|
|||||||
|
|
||||||
respond_with(@post_disapprovals)
|
respond_with(@post_disapprovals)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@post_disapproval = authorize PostDisapproval.find(params[:id])
|
||||||
|
respond_with(@post_disapproval)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@post_disapproval = authorize PostDisapproval.find(params[:id])
|
||||||
|
@post_disapproval.update(permitted_attributes(@post_disapproval))
|
||||||
|
respond_with(@post_disapproval) do |fmt|
|
||||||
|
fmt.html { redirect_to post_path(@post_disapproval.post) }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ class PostsController < ApplicationController
|
|||||||
@child_posts = @post.children
|
@child_posts = @post.children
|
||||||
@child_posts = @child_posts.undeleted unless include_deleted
|
@child_posts = @child_posts.undeleted unless include_deleted
|
||||||
@sibling_posts = @sibling_posts.includes(:media_asset)
|
@sibling_posts = @sibling_posts.includes(:media_asset)
|
||||||
|
|
||||||
|
if CurrentUser.user.is_approver?
|
||||||
|
@previous_disapproval = @post.disapprovals.select { |disapproval| disapproval.user_id == CurrentUser.user.id }.first
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_with(@post) do |format|
|
respond_with(@post) do |format|
|
||||||
|
|||||||
@@ -267,10 +267,6 @@ class Post < ApplicationRecord
|
|||||||
!is_active? && uploader != user
|
!is_active? && uploader != user
|
||||||
end
|
end
|
||||||
|
|
||||||
def disapproved_by?(user)
|
|
||||||
PostDisapproval.exists?(user_id: user.id, post_id: id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def autoban
|
def autoban
|
||||||
if has_tag?("banned_artist") || has_tag?("paid_reward")
|
if has_tag?("banned_artist") || has_tag?("paid_reward")
|
||||||
self.is_banned = true
|
self.is_banned = true
|
||||||
|
|||||||
@@ -9,10 +9,22 @@ class PostDisapprovalPolicy < ApplicationPolicy
|
|||||||
user.is_moderator? || record.user_id == user.id
|
user.is_moderator? || record.user_id == user.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def permitted_attributes
|
def permitted_attributes_for_create
|
||||||
[:post_id, :reason, :message]
|
[:post_id, :reason, :message]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def permitted_attributes_for_update
|
||||||
|
[:reason, :message]
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit?
|
||||||
|
update?
|
||||||
|
end
|
||||||
|
|
||||||
|
def update?
|
||||||
|
unbanned? && record.post.in_modqueue? && record.user_id == user.id
|
||||||
|
end
|
||||||
|
|
||||||
def api_attributes
|
def api_attributes
|
||||||
attributes = super
|
attributes = super
|
||||||
attributes -= [:user_id] unless can_view_creator?
|
attributes -= [:user_id] unless can_view_creator?
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
<div class="quick-mod">
|
<div class="quick-mod">
|
||||||
<%= link_to_if post.is_approvable?, "Approve", post_approvals_path(post_id: post.id), method: :post, remote: true, class: "approve-link btn" %> |
|
<%= link_to_if post.is_approvable?, "Approve", post_approvals_path(post_id: post.id), method: :post, remote: true, class: "approve-link btn" %> |
|
||||||
<%= link_to "Breaks Rules", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "breaks_rules" }), method: :post, remote: true, class: "disapprove-link btn" %> |
|
<% PostDisapproval::REASONS.each do |reason| %>
|
||||||
<%= link_to "Poor Quality", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "poor_quality" }), method: :post, remote: true, class: "disapprove-link btn" %> |
|
<% if @previous_disapproval&.reason == reason %>
|
||||||
<%= link_to "No Interest", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "disinterest" }), method: :post, remote: true, class: "disapprove-link btn" %> |
|
<%= reason.humanize %> |
|
||||||
|
<% elsif @previous_disapproval %>
|
||||||
|
<%= link_to reason.humanize, post_disapproval_path(@previous_disapproval, post_disapproval: { reason: reason }), method: :put, remote: true, class: "disapprove-link disapprove-link-#{reason.gsub("_", "-")} btn" %> |
|
||||||
|
<% else %>
|
||||||
|
<%= link_to reason.humanize, post_disapprovals_path(post_disapproval: { post_id: post.id, reason: reason }), method: :post, remote: true, class: "disapprove-link disapprove-link-#{reason.gsub("_", "-")} btn" %> |
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
<%= link_to "Detailed Rejection", "#", "data-post-id" => post.id, class: "detailed-rejection-link btn" %>
|
<%= link_to "Detailed Rejection", "#", "data-post-id" => post.id, class: "detailed-rejection-link btn" %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
<div id="detailed-rejection-dialog" title="Detailed Rejection" style="display: none;">
|
<div id="detailed-rejection-dialog" title="Detailed Rejection" style="display: none;">
|
||||||
<p>You can supply a short message to the uploader explaining why you rejected this upload.</p>
|
<p>You can supply a short message to the uploader explaining why you rejected this upload.</p>
|
||||||
|
|
||||||
<%= edit_form_for(PostDisapproval.new, url: post_disapprovals_path, remote: true, html: { id: "detailed-rejection-form" }) do |f| %>
|
<% if @previous_disapproval %>
|
||||||
<%= f.hidden_field :post_id, value: "x" %>
|
<%= edit_form_for(@previous_disapproval, remote: true, html: { id: "detailed-rejection-form" }) do |f| %>
|
||||||
<%= f.input :reason, collection: PostDisapproval::REASONS.map { |x| [x.humanize, x] } %>
|
<%= f.input :reason, collection: PostDisapproval::REASONS.map { |x| [x.humanize, x] }, :selected => @previous_disapproval.reason %>
|
||||||
<%= f.input :message, as: :string %>
|
<%= f.input :message, as: :string, :input_html => {:value => @previous_disapproval.message } %>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= edit_form_for(PostDisapproval.new, remote: true, html: { id: "detailed-rejection-form" }) do |f| %>
|
||||||
|
<%= f.hidden_field :post_id, value: "x" %>
|
||||||
|
<%= f.input :reason, collection: PostDisapproval::REASONS.map { |x| [x.humanize, x] } %>
|
||||||
|
<%= f.input :message, as: :string %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
1
app/views/post_disapprovals/update.js.erb
Normal file
1
app/views/post_disapprovals/update.js.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
location.reload();
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
<%= render "post_disapprovals/counts", disapprovals: post.disapprovals.order(id: :asc), post: post %>
|
<%= render "post_disapprovals/counts", disapprovals: post.disapprovals.order(id: :asc), post: post %>
|
||||||
|
|
||||||
<% if policy(PostDisapproval).create? && !post.disapproved_by?(CurrentUser.user) %>
|
<% if CurrentUser.user.is_approver? %>
|
||||||
<%= render "modqueue/quick_mod", post: post %>
|
<%= render "modqueue/quick_mod", post: post %>
|
||||||
<%= render "post_disapprovals/detailed_rejection_dialog" %>
|
<%= render "post_disapprovals/detailed_rejection_dialog" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -51,11 +51,6 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if policy(PostApproval).create? %>
|
<% if policy(PostApproval).create? %>
|
||||||
<% if post.is_approvable? %>
|
|
||||||
<li id="post-option-approve"><%= link_to (post.is_deleted? ? "Undelete" : "Approve"), post_approvals_path(post_id: post.id), remote: true, method: :post, "data-shortcut": "shift+o", "data-confirm": "Are you sure you want to approve this post?" %></li>
|
|
||||||
<li id="post-option-disapprove"><%= link_to "Hide from queue", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "disinterest" }), remote: true, method: :post %></li>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if post.is_deleted? && policy(post).move_favorites? %>
|
<% if post.is_deleted? && policy(post).move_favorites? %>
|
||||||
<li id="post-option-move-favorites"><%= link_to "Move favorites", confirm_move_favorites_moderator_post_post_path(post_id: post.id) %></li>
|
<li id="post-option-move-favorites"><%= link_to "Move favorites", confirm_move_favorites_moderator_post_post_path(post_id: post.id) %></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ Rails.application.routes.draw do
|
|||||||
resources :post_appeals
|
resources :post_appeals
|
||||||
resources :post_flags
|
resources :post_flags
|
||||||
resources :post_approvals, only: [:create, :index]
|
resources :post_approvals, only: [:create, :index]
|
||||||
resources :post_disapprovals, only: [:create, :show, :index]
|
resources :post_disapprovals
|
||||||
resources :post_versions, :only => [:index, :search] do
|
resources :post_versions, :only => [:index, :search] do
|
||||||
member do
|
member do
|
||||||
put :undo
|
put :undo
|
||||||
|
|||||||
@@ -85,5 +85,28 @@ class PostDisapprovalsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
should respond_to_search(user_name: "eiki").with { @user_disapproval }
|
should respond_to_search(user_name: "eiki").with { @user_disapproval }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "update action" do
|
||||||
|
setup do
|
||||||
|
@post = create(:post, is_pending: true)
|
||||||
|
@approver = create(:approver, name: "alice-san")
|
||||||
|
@another_approver = create(:approver, name: "bob-kun")
|
||||||
|
@post_disapproval = create(:post_disapproval, post: @post, user: @approver, reason: "poor_quality")
|
||||||
|
end
|
||||||
|
|
||||||
|
should "allow editing of disapprovals" do
|
||||||
|
put_auth post_disapproval_path(@post_disapproval), @approver, params: {post_disapproval: {reason: "breaks_rules"}}
|
||||||
|
|
||||||
|
assert_redirected_to(@post)
|
||||||
|
assert_equal("breaks_rules", @post_disapproval.reload.reason)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not allow editing by another user" do
|
||||||
|
put_auth post_disapproval_path(@post_disapproval), @another_approver, params: {post_disapproval: {reason: "disinterest"}}
|
||||||
|
|
||||||
|
assert_response 403
|
||||||
|
assert_equal("poor_quality", @post_disapproval.reload.reason)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user