Post#approve!: move approving logic to post_approval.rb.

This commit is contained in:
evazion
2017-04-03 13:30:13 -05:00
parent 258fc37bfe
commit db0bcf08b9
2 changed files with 10 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ class PostApproval < ActiveRecord::Base
belongs_to :post, inverse_of: :approvals
validate :validate_approval
after_create :approve_post
def self.prune!
where("created_at < ?", 1.month.ago).delete_all
@@ -21,4 +22,11 @@ class PostApproval < ActiveRecord::Base
errors.add(:base, "You have previously approved this post and cannot approve it again")
end
end
def approve_post
ModAction.log("undeleted post ##{id}") if post.is_deleted
post.flags.each(&:resolve!)
post.update({ approver: user, is_flagged: false, is_pending: false, is_deleted: false }, without_protection: true)
end
end