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:
evazion
2020-04-03 16:37:48 -05:00
parent fde42022c0
commit d435795b73
4 changed files with 52 additions and 1 deletions

View File

@@ -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)