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)

View File

@@ -15,6 +15,7 @@ class PostFlag < ApplicationRecord
validate :validate_post, on: :create
validates :creator_id, uniqueness: { scope: :post_id, on: :create, unless: :is_deletion, message: "have already flagged this post" }
before_save :update_post
after_create :prune_disapprovals
attr_accessor :is_deletion
enum status: {
@@ -90,6 +91,11 @@ class PostFlag < ApplicationRecord
end
end
def prune_disapprovals
return if is_deletion
PostDisapproval.where(post: post).delete_all
end
def update_post
post.update_column(:is_flagged, true) unless post.is_flagged?
end