mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 13:31:44 +08:00
a48f7ba61c
It used to simply say "title is invalid" without giving any hint what the problem could be. This commit adds different errors messages for all caps titles, low entropy titles or titles with very long words.
23 lines
642 B
Ruby
23 lines
642 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'text_sentinel'
|
|
require 'text_cleaner'
|
|
|
|
class QualityTitleValidator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
sentinel = TextSentinel.title_sentinel(value)
|
|
|
|
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
|
|
end
|
|
end
|