Fix #4315: Disapproval messages aren't striped of spaces.

Set blank disapproval messages to null to prevent them from showing up
in wildcard searches.
This commit is contained in:
evazion
2020-03-03 04:26:39 -06:00
parent 143bfdfb5b
commit b9939c6356
3 changed files with 14 additions and 3 deletions

View File

@@ -6,8 +6,8 @@ class PostDisapproval < ApplicationRecord
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
scope :with_message, -> {where("message is not null and message <> ''")}
scope :without_message, -> {where("message is null or message = ''")}
scope :with_message, -> { where.not(message: nil) }
scope :without_message, -> { where(message: nil) }
scope :breaks_rules, -> {where(:reason => "breaks_rules")}
scope :poor_quality, -> {where(:reason => "poor_quality")}
scope :disinterest, -> {where(:reason => ["disinterest", "legacy"])}
@@ -61,6 +61,11 @@ class PostDisapproval < ApplicationRecord
[:user, :post]
end
def message=(message)
message = nil if message.blank?
super(message)
end
def can_view_creator?(user)
user.is_moderator? || user_id == user.id
end