posts: add disapproved:<reason> edit metatag.
* Allow tagging a post with a `disapproved:<disinterest|breaks_rules|poor_quality>` to disapprove it. * Disallow disapproving active posts. Fixes #4384.
This commit is contained in:
@@ -6,6 +6,7 @@ class PostDisapproval < ApplicationRecord
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"
|
||||
validates_inclusion_of :reason, in: REASONS
|
||||
validate :validate_disapproval
|
||||
|
||||
scope :with_message, -> { where.not(message: nil) }
|
||||
scope :without_message, -> { where(message: nil) }
|
||||
@@ -62,6 +63,12 @@ class PostDisapproval < ApplicationRecord
|
||||
[:user, :post]
|
||||
end
|
||||
|
||||
def validate_disapproval
|
||||
if post.status == "active"
|
||||
errors[:post] << "is already active and cannot be disapproved"
|
||||
end
|
||||
end
|
||||
|
||||
def message=(message)
|
||||
message = nil if message.blank?
|
||||
super(message)
|
||||
|
||||
Reference in New Issue
Block a user