Merge pull request #5114 from nonamethanks/editable-post-disapprovals

Allow post disapprovals to be edited
This commit is contained in:
evazion
2022-04-17 22:54:57 -05:00
committed by GitHub
11 changed files with 76 additions and 19 deletions

View File

@@ -17,4 +17,17 @@ class PostDisapprovalsController < ApplicationController
respond_with(@post_disapprovals)
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

View File

@@ -38,6 +38,10 @@ class PostsController < ApplicationController
@child_posts = @post.children
@child_posts = @child_posts.undeleted unless include_deleted
@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
respond_with(@post) do |format|

View File

@@ -267,10 +267,6 @@ class Post < ApplicationRecord
!is_active? && uploader != user
end
def disapproved_by?(user)
PostDisapproval.exists?(user_id: user.id, post_id: id)
end
def autoban
if has_tag?("banned_artist") || has_tag?("paid_reward")
self.is_banned = true

View File

@@ -9,10 +9,22 @@ class PostDisapprovalPolicy < ApplicationPolicy
user.is_moderator? || record.user_id == user.id
end
def permitted_attributes
def permitted_attributes_for_create
[:post_id, :reason, :message]
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
attributes = super
attributes -= [:user_id] unless can_view_creator?

View File

@@ -1,7 +1,13 @@
<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 "Breaks Rules", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "breaks_rules" }), method: :post, remote: true, class: "disapprove-link btn" %> |
<%= link_to "Poor Quality", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "poor_quality" }), method: :post, remote: true, class: "disapprove-link btn" %> |
<%= link_to "No Interest", post_disapprovals_path(post_disapproval: { post_id: post.id, reason: "disinterest" }), method: :post, remote: true, class: "disapprove-link btn" %> |
<% PostDisapproval::REASONS.each do |reason| %>
<% if @previous_disapproval&.reason == reason %>
<%= 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" %>
</div>

View File

@@ -1,9 +1,16 @@
<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>
<%= edit_form_for(PostDisapproval.new, url: post_disapprovals_path, 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 %>
<% if @previous_disapproval %>
<%= 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] }, :selected => @previous_disapproval.reason %>
<%= 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 %>
</div>

View File

@@ -0,0 +1 @@
location.reload();

View File

@@ -18,7 +18,7 @@
<%= 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 "post_disapprovals/detailed_rejection_dialog" %>
<% end %>

View File

@@ -51,11 +51,6 @@
<% end %>
<% 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? %>
<li id="post-option-move-favorites"><%= link_to "Move favorites", confirm_move_favorites_moderator_post_post_path(post_id: post.id) %></li>
<% end %>