discourse/lib/validators/censored_words_validator.rb

16 lines
488 B
Ruby
Raw Normal View History

class CensoredWordsValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if value =~ /#{SiteSetting.censored_words}/i
record.errors.add(
attribute, :contains_censored_words,
censored_words: SiteSetting.censored_words
)
elsif value =~ /#{SiteSetting.censored_pattern}/i
record.errors.add(
attribute, :matches_censored_pattern,
censored_pattern: SiteSetting.censored_pattern
)
end
end
end