approvals: remove post undelete endpoint.
Remove `POST /moderator/post/undelete` endpoint. Replace it with `POST /post_approvals` instead. Fixes it so that undeleting a post has the same behavior as approving a post. Namely, it reloads the page instead of just flashing a "Post was undeleted" message.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
module Moderator
|
||||
module Post
|
||||
class PostsController < ApplicationController
|
||||
before_action :approver_only, :only => [:delete, :undelete, :move_favorites, :ban, :unban, :confirm_delete, :confirm_move_favorites, :confirm_ban]
|
||||
before_action :approver_only, :only => [:delete, :move_favorites, :ban, :unban, :confirm_delete, :confirm_move_favorites, :confirm_ban]
|
||||
before_action :admin_only, :only => [:expunge]
|
||||
skip_before_action :api_check
|
||||
|
||||
@@ -19,11 +19,6 @@ module Moderator
|
||||
redirect_to(post_path(@post))
|
||||
end
|
||||
|
||||
def undelete
|
||||
@post = ::Post.find(params[:id])
|
||||
@post.approve!
|
||||
end
|
||||
|
||||
def confirm_move_favorites
|
||||
@post = ::Post.find(params[:id])
|
||||
end
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
$("#c-posts #delete").show();
|
||||
$("#c-posts #undelete").hide();
|
||||
Danbooru.notice("Post was undeleted");
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
<% if CurrentUser.can_approve_posts? %>
|
||||
<% if post.is_deleted? %>
|
||||
<li id="post-option-undelete"><%= link_to "Undelete", undelete_moderator_post_post_path(post_id: post.id), remote: true, method: :post, "data-confirm": "Are you sure you want to undelete this post?" %></li>
|
||||
<li id="post-option-undelete"><%= link_to "Undelete", post_approvals_path(post_id: post.id), remote: true, method: :post, "data-confirm": "Are you sure you want to undelete this post?" %></li>
|
||||
<% if post.fav_count > 0 && post.parent_id %>
|
||||
<li id="post-option-move-favorites"><%= link_to "Move favorites", confirm_move_favorites_moderator_post_post_path(post_id: post.id) %></li>
|
||||
<% end %>
|
||||
|
||||
@@ -19,12 +19,11 @@ Rails.application.routes.draw do
|
||||
get :random
|
||||
end
|
||||
end
|
||||
resources :posts, :only => [:delete, :undelete, :expunge, :confirm_delete] do
|
||||
resources :posts, :only => [:delete, :expunge, :confirm_delete] do
|
||||
member do
|
||||
get :confirm_delete
|
||||
post :expunge
|
||||
post :delete
|
||||
post :undelete
|
||||
get :confirm_move_favorites
|
||||
post :move_favorites
|
||||
get :confirm_ban
|
||||
|
||||
@@ -35,20 +35,6 @@ module Moderator
|
||||
end
|
||||
end
|
||||
|
||||
context "undelete action" do
|
||||
should "render" do
|
||||
as_user do
|
||||
@post.update(is_deleted: true)
|
||||
end
|
||||
assert_difference(-> { PostApproval.count }, 1) do
|
||||
post_auth undelete_moderator_post_post_path(@post), @admin, params: {:format => "js"}
|
||||
end
|
||||
|
||||
assert_response :success
|
||||
assert(!@post.reload.is_deleted?)
|
||||
end
|
||||
end
|
||||
|
||||
context "confirm_move_favorites action" do
|
||||
should "render" do
|
||||
get_auth confirm_ban_moderator_post_post_path(@post), @admin
|
||||
|
||||
@@ -7,12 +7,24 @@ class PostApprovalsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
|
||||
context "create action" do
|
||||
should "render" do
|
||||
@post = create(:post, is_pending: true)
|
||||
post_auth post_approvals_path(post_id: @post.id, format: :js), @approver
|
||||
context "for a pending post" do
|
||||
should "approve the post" do
|
||||
@post = create(:post, is_pending: true)
|
||||
post_auth post_approvals_path(post_id: @post.id, format: :js), @approver
|
||||
|
||||
assert_response :success
|
||||
assert(!@post.reload.is_pending?)
|
||||
assert_response :success
|
||||
assert(!@post.reload.is_pending?)
|
||||
end
|
||||
end
|
||||
|
||||
context "for a deleted post" do
|
||||
should "undelete the post" do
|
||||
@post = create(:post, is_deleted: true)
|
||||
post_auth post_approvals_path(post_id: @post.id, format: :js), @approver
|
||||
|
||||
assert_response :success
|
||||
assert(!@post.reload.is_deleted?)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user