2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-05-23 00:52:12 -04:00
|
|
|
require 'text_sentinel'
|
|
|
|
require 'text_cleaner'
|
|
|
|
|
|
|
|
class QualityTitleValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
2022-10-04 14:55:21 -04:00
|
|
|
return if Discourse.static_doc_topic_ids.include?(record.id) && record.acting_user&.admin?
|
|
|
|
|
2013-05-23 00:52:12 -04:00
|
|
|
sentinel = TextSentinel.title_sentinel(value)
|
2020-11-11 08:11:36 -05:00
|
|
|
|
|
|
|
if !sentinel.valid?
|
|
|
|
if !sentinel.seems_meaningful?
|
|
|
|
record.errors.add(attribute, :is_invalid_meaningful)
|
|
|
|
elsif !sentinel.seems_unpretentious?
|
|
|
|
record.errors.add(attribute, :is_invalid_unpretentious)
|
|
|
|
elsif !sentinel.seems_quiet?
|
|
|
|
record.errors.add(attribute, :is_invalid_quiet)
|
|
|
|
else
|
|
|
|
record.errors.add(attribute, :is_invalid)
|
|
|
|
end
|
|
|
|
end
|
2013-05-23 00:52:12 -04:00
|
|
|
end
|
|
|
|
end
|