posts: rework post deletion to use dialog box.

Rework post deletion from using a separate page to using a dialog box,
like flagging.

* Add `DELETE /posts/:id` endpoint.
* Remove `POST /moderator/post/posts/:id/delete` endpoint.
This commit is contained in:
evazion
2020-08-03 19:28:10 -05:00
parent f1b0e31923
commit bca1f122d0
10 changed files with 69 additions and 62 deletions

View File

@@ -4,18 +4,6 @@ module Moderator
skip_before_action :api_check
respond_to :html, :json, :xml, :js
def confirm_delete
@post = ::Post.find(params[:id])
end
def delete
@post = authorize ::Post.find(params[:id])
if params[:commit] == "Delete"
@post.delete!(params[:reason], :move_favorites => params[:move_favorites].present?)
end
redirect_to(post_path(@post))
end
def confirm_move_favorites
@post = ::Post.find(params[:id])
end

View File

@@ -56,6 +56,18 @@ class PostsController < ApplicationController
respond_with_post_after_update(@post)
end
def destroy
@post = authorize Post.find(params[:id])
if params[:commit] == "Delete"
move_favorites = params.dig(:post, :move_favorites).to_s.truthy?
@post.delete!(params.dig(:post, :reason), move_favorites: move_favorites)
flash[:notice] = "Post deleted"
end
respond_with_post_after_update(@post)
end
def revert
@post = authorize Post.find(params[:id])
@version = @post.versions.find(params[:version_id])

View File

@@ -31,6 +31,10 @@ class PostPolicy < ApplicationPolicy
user.is_approver? && !record.is_deleted?
end
def destroy?
delete?
end
def ban?
user.is_approver? && !record.is_banned?
end

View File

@@ -1,26 +0,0 @@
<h1>Delete Post</h1>
<div>
<%= PostPresenter.preview(@post, show_deleted: true) %>
</div>
<%= form_tag(delete_moderator_post_post_path, :style => "clear: both;", :class => "simple_form") do %>
<% if @post.parent_id %>
<div class="input">
<label for="move_favorites">
<%= check_box_tag "move_favorites" %>
Move favorites to parent?
</label>
</div>
<% end %>
<p style="font-weight: bold;">Note: If the reason you are planning to delete this post is because it is from a banned artist, please <%= link_to "ban", confirm_ban_moderator_post_post_path(@post) %> this post instead of deleting it.</p>
<div class="input">
<label for="reason">Reason</label>
<%= text_area_tag "reason" %>
</div>
<%= submit_tag "Delete" %>
<%= submit_tag "Cancel" %>
<% end %>

View File

@@ -0,0 +1,5 @@
<% if params[:commit] == "Delete" %>
location.reload();
<% else %>
Danbooru.Utility.dialog("Delete Post", "<%= j render "posts/partials/show/delete_dialog", post: @post %>");
<% end %>

View File

@@ -0,0 +1,9 @@
<div class="delete-post-dialog-body">
<%= edit_form_for(post, method: :delete, remote: true) do |f| %>
<input type="hidden" name="commit" value="Delete">
<%= f.input :reason, as: :dtext, inline: true, input_html: { value: "" } %>
<% if post.parent_id.present? %>
<%= f.input :move_favorites, label: "Move favorites to parent", as: :boolean, input_html: { checked: false } %>
<% end %>
<% end %>
</div>

View File

@@ -64,7 +64,7 @@
<li id="post-option-move-favorites"><%= link_to "Move favorites", confirm_move_favorites_moderator_post_post_path(post_id: post.id) %></li>
<% end %>
<% elsif policy(post).delete? %>
<li id="post-option-delete"><%= link_to "Delete", confirm_delete_moderator_post_post_path(post_id: post.id) %></li>
<li id="post-option-delete"><%= link_to "Delete", post, method: :delete, remote: true %></li>
<% end %>
<% if post.is_approvable? && !post.is_deleted? %>