fixes #2448: Approvers can undelete posts they already approved/uploaded
This commit is contained in:
@@ -3,7 +3,7 @@ module Moderator
|
||||
class PostsController < ApplicationController
|
||||
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
|
||||
rescue_from ::PostFlag::Error, ::Post::ApprovalError, :with => :rescue_exception
|
||||
|
||||
def confirm_delete
|
||||
@post = ::Post.find(params[:id])
|
||||
|
||||
@@ -1214,7 +1214,6 @@ class Post < ActiveRecord::Base
|
||||
give_favorites_to_parent if options[:move_favorites]
|
||||
update_parent_on_save
|
||||
|
||||
|
||||
unless options[:without_mod_action]
|
||||
if options[:reason]
|
||||
ModAction.create(:description => "deleted post ##{id}, reason: #{options[:reason]}")
|
||||
@@ -1231,6 +1230,14 @@ class Post < ActiveRecord::Base
|
||||
return false
|
||||
end
|
||||
|
||||
if !CurrentUser.is_admin?
|
||||
if approver_id == CurrentUser.id
|
||||
raise ApprovalError.new("You have previously approved this post and cannot undelete it")
|
||||
elsif uploader_id == CurrentUser.id
|
||||
raise ApprovalError.new("You cannot undelete a post you uploaded")
|
||||
end
|
||||
end
|
||||
|
||||
self.is_deleted = false
|
||||
self.approver_id = CurrentUser.id
|
||||
save
|
||||
|
||||
Reference in New Issue
Block a user