Posts: prune disapprovals on new appeal or flag

This commit is contained in:
nonamethanks
2022-04-11 15:44:54 +02:00
parent 05261bf6d7
commit 63bd5daa3b
3 changed files with 71 additions and 12 deletions

View File

@@ -8,6 +8,7 @@ class PostAppeal < ApplicationRecord
validate :validate_post_is_appealable, on: :create
validate :validate_creator_is_not_limited, on: :create
validates :creator, uniqueness: { scope: :post, message: "have already appealed this post" }, on: :create
after_create :prune_disapprovals
enum status: {
pending: 0,
@@ -17,6 +18,10 @@ class PostAppeal < ApplicationRecord
scope :expired, -> { pending.where("post_appeals.created_at < ?", Danbooru.config.moderation_period.ago) }
def prune_disapprovals
PostDisapproval.where(post: post).delete_all
end
module SearchMethods
def search(params)
q = search_attributes(params, :id, :created_at, :updated_at, :reason, :status, :creator, :post)