flags: move flagging inside Post#delete!

This commit is contained in:
evazion
2017-05-17 22:48:01 -05:00
parent 6bebc3f694
commit 565945ab7b
4 changed files with 21 additions and 26 deletions

View File

@@ -14,8 +14,7 @@ module Moderator
def delete
@post = ::Post.find(params[:id])
if params[:commit] == "Delete"
@post.flag!(params[:reason], :is_deletion => true)
@post.delete!(:reason => params[:reason], :move_favorites => params[:move_favorites].present?)
@post.delete!(params[:reason], :move_favorites => params[:move_favorites].present?)
end
redirect_to(post_path(@post))
end

View File

@@ -13,11 +13,10 @@ protected
CurrentUser.scoped(User.system, "127.0.0.1") do
Post.where("is_deleted = ? and is_pending = ? and created_at < ?", false, true, 3.days.ago).each do |post|
begin
post.flag!("Unapproved in three days")
post.delete!("Unapproved in three days")
rescue PostFlag::Error
# swallow
end
post.delete!
end
end
end
@@ -27,11 +26,10 @@ protected
Post.where("is_deleted = ? and is_flagged = ?", false, true).each do |post|
if post.flags.unresolved.old.any?
begin
post.flag!("Unapproved in three days after returning to moderation queue")
post.delete!("Unapproved in three days after returning to moderation queue")
rescue PostFlag::Error
# swallow
end
post.delete!
end
end
end

View File

@@ -1355,7 +1355,7 @@ class Post < ActiveRecord::Base
end
ModAction.log("permanently deleted post ##{id}")
delete!(:without_mod_action => true)
delete!("Permanently deleted post ##{id}", :without_mod_action => true)
Post.without_timeout do
give_favorites_to_parent
update_children_on_destroy
@@ -1377,13 +1377,15 @@ class Post < ActiveRecord::Base
ModAction.log("unbanned post ##{id}")
end
def delete!(options = {})
def delete!(reason, options = {})
if is_status_locked?
self.errors.add(:is_status_locked, "; cannot delete post")
return false
end
Post.transaction do
flag!(reason, is_deletion: true)
self.is_deleted = true
self.is_pending = false
self.is_flagged = false
@@ -1398,11 +1400,7 @@ class Post < ActiveRecord::Base
update_parent_on_save
unless options[:without_mod_action]
if options[:reason]
ModAction.log("deleted post ##{id}, reason: #{options[:reason]}")
else
ModAction.log("deleted post ##{id}")
end
ModAction.log("deleted post ##{id}, reason: #{reason}")
end
end
end