Allow moving favorites for already deleted post

This commit is contained in:
Toks 2015-07-07 11:08:32 -04:00
parent 8ea095e06e
commit 7c90fca006
4 changed files with 30 additions and 1 deletions

View File

@ -1,7 +1,7 @@
module Moderator
module Post
class PostsController < ApplicationController
before_filter :moderator_only, :only => [:delete, :undelete, :ban, :unban, :confirm_delete, :confirm_ban]
before_filter :moderator_only, :only => [:delete, :undelete, :move_favorites, :ban, :unban, :confirm_delete, :confirm_move_favorites, :confirm_ban]
before_filter :admin_only, :only => [:expunge]
rescue_from ::PostFlag::Error, :with => :rescue_exception
@ -23,6 +23,18 @@ module Moderator
@post.undelete!
end
def confirm_move_favorites
@post = ::Post.find(params[:id])
end
def move_favorites
@post = ::Post.find(params[:id])
if params[:commit] == "Submit"
@post.give_favorites_to_parent
end
redirect_to(post_path(@post))
end
def expunge
@post = ::Post.find(params[:id])
@post.expunge!

View File

@ -0,0 +1,12 @@
<h1>Move Favorites to Parent</h1>
<div>
<%= PostPresenter.preview(@post, :tags => "status:any") %>
</div>
<p style="clear: both;">This will move all the post's favorites to its parent post. Are you sure?</p>
<%= form_tag(move_favorites_moderator_post_post_path, :style => "clear: both;", :class => "simple_form") do %>
<%= submit_tag "Submit" %>
<%= submit_tag "Cancel" %>
<% end %>

View File

@ -31,6 +31,9 @@
<% if CurrentUser.can_approve_posts? %>
<% if post.is_deleted? %>
<li><%= link_to "Undelete", undelete_moderator_post_post_path(:post_id => post.id), :remote => true, :method => :post, :id => "undelete" %></li>
<% if post.fav_count > 0 && post.parent_id %>
<li><%= link_to "Move favorites", confirm_move_favorites_moderator_post_post_path(:post_id => post.id) %></li>
<% end %>
<% else %>
<li><%= link_to "Delete", confirm_delete_moderator_post_post_path(:post_id => post.id) %></li>
<% end %>

View File

@ -26,6 +26,8 @@ Rails.application.routes.draw do
post :expunge
post :delete
post :undelete
get :confirm_move_favorites
post :move_favorites
get :confirm_ban
post :ban
post :unban