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:
@@ -753,7 +753,7 @@ class Post < ApplicationRecord
|
||||
def filter_metatags(tags)
|
||||
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent|-?locked):/i}
|
||||
tags = apply_categorization_metatags(tags)
|
||||
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-child|-favgroup|favgroup|upvote|downvote|status|-status):/i}
|
||||
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-child|-favgroup|favgroup|upvote|downvote|status|-status|disapproved):/i}
|
||||
apply_pre_metatags
|
||||
return tags
|
||||
end
|
||||
@@ -815,6 +815,10 @@ class Post < ApplicationRecord
|
||||
raise User::PrivilegeError unless CurrentUser.is_approver?
|
||||
unban!
|
||||
|
||||
when /^disapproved:(.+)$/i
|
||||
raise User::PrivilegeError unless CurrentUser.is_approver?
|
||||
disapprovals.create!(user: CurrentUser.user, reason: $1.downcase)
|
||||
|
||||
when /^child:none$/i
|
||||
children.each do |post|
|
||||
post.update!(parent_id: nil)
|
||||
|
||||
@@ -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