Files
danbooru/app/models/post_approval.rb
evazion 0a0a85ee70 Fix #4568: Send appealed posts back to the mod queue
* Include appealed posts in the modqueue.

* Add `status` field to appeals. Appeals start out as `pending`, then
  become `rejected` if the post isn't approved within three days. If the
  post is approved, the appeal's status becomes `succeeded`.

* Add `status` field to flags. Flags start out as `pending` then become
  `rejected` if the post is approved within three days. If the post
  isn't approved, the flag's status becomes `succeeded`.

* Leave behind a "Unapproved in three days" dummy flag when an appeal
  goes unapproved, just like when a pending post is unapproved.

* Only allow deleted posts to be appealed. Don't allow flagged posts to be appealed.

* Add `status:appealed` metatag. `status:appealed` is separate from `status:pending`.

* Include appealed posts in `status:modqueue`. Search `status:modqueue order:modqueue`
  to view the modqueue as a normal search.

* Retroactively set old flags and appeals as succeeded or rejected. This
  may not be correct for posts that were appealed or flagged multiple
  times. This is difficult to set correctly because we don't have
  approval records for old posts, so we can't tell the actual outcome of
  old flags and appeals.

* Deprecate the `is_resolved` field on post flags. A resolved flag is a
  flag that isn't pending.

* Known bug: appealed posts have a black border instead of a blue
  border. Checking whether a post has been appealed would require either
  an extra query on the posts/index page, or an is_appealed flag on
  posts, neither of which are very desirable.

* Known bug: you can't use `status:appealed` in blacklists, for the same
  reason as above.
2020-08-06 20:55:45 -05:00

50 lines
1.3 KiB
Ruby

class PostApproval < ApplicationRecord
belongs_to :user
belongs_to :post, inverse_of: :approvals
validate :validate_approval
after_create :approve_post
def validate_approval
post.lock!
if post.is_status_locked?
errors.add(:post, "is locked and cannot be approved")
end
if post.is_active?
errors.add(:post, "is already active and cannot be approved")
end
if post.uploader == user
errors.add(:base, "You cannot approve a post you uploaded")
end
if post.approver == user || post.approvals.where(user: user).exists?
errors.add(:base, "You have previously approved this post and cannot approve it again")
end
end
def approve_post
is_undeletion = post.is_deleted
post.flags.pending.update!(status: :rejected)
post.appeals.pending.update!(status: :succeeded)
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
ModAction.log("undeleted post ##{post_id}", :post_undelete) if is_undeletion
post.uploader.upload_limit.update_limit!(post, incremental: !is_undeletion)
end
def self.search(params)
q = super
q = q.search_attributes(params, :user, :post)
q.apply_default_order(params)
end
def self.available_includes
[:user, :post]
end
end