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

@@ -321,20 +321,8 @@ class Post < ActiveRecord::Base
end
end
def approve!
flags.each {|x| x.resolve!}
self.is_flagged = false
self.is_pending = false
self.is_deleted = false
self.approver_id = CurrentUser.id
PostApproval.create(user_id: CurrentUser.id, post_id: id)
if is_deleted_was == true
ModAction.log("undeleted post ##{id}")
end
save!
def approve!(approver = CurrentUser.user)
approvals.create!(user: approver)
end
def approved_by?(user)

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