2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-05 08:59:27 +08:00
discourse/lib/validators/censored_words_validator.rb
2017-01-09 17:08:24 +08:00

15 lines
566 B
Ruby

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