Regexp is available in sensitive_words
This commit is contained in:
parent
303c14acad
commit
1a5f8964e1
2 changed files with 24 additions and 2 deletions
|
@ -11,6 +11,14 @@ module Admin
|
|||
def create
|
||||
authorize :sensitive_words, :create?
|
||||
|
||||
begin
|
||||
test_words
|
||||
rescue
|
||||
flash[:alert] = I18n.t('admin.ng_words.test_error')
|
||||
redirect_to after_update_redirect_path
|
||||
return
|
||||
end
|
||||
|
||||
@admin_settings = Form::AdminSettings.new(settings_params)
|
||||
|
||||
if @admin_settings.save
|
||||
|
@ -23,6 +31,12 @@ module Admin
|
|||
|
||||
private
|
||||
|
||||
def test_words
|
||||
sensitive_words = settings_params['sensitive_words'].split(/\r\n|\r|\n/)
|
||||
sensitive_words_for_full = settings_params['sensitive_words_for_full'].split(/\r\n|\r|\n/)
|
||||
Admin::NgWord.reject_with_custom_words?('Sample text', sensitive_words + sensitive_words_for_full)
|
||||
end
|
||||
|
||||
def after_update_redirect_path
|
||||
admin_sensitive_words_path
|
||||
end
|
||||
|
|
|
@ -4,8 +4,8 @@ class Admin::SensitiveWord
|
|||
class << self
|
||||
def sensitive?(text, spoiler_text)
|
||||
exposure_text = (spoiler_text.presence || text)
|
||||
(spoiler_text.blank? && sensitive_words.any? { |word| text.include?(word) }) ||
|
||||
sensitive_words_for_full.any? { |word| exposure_text.include?(word) }
|
||||
(spoiler_text.blank? && sensitive_words.any? { |word| include?(text, word) }) ||
|
||||
sensitive_words_for_full.any? { |word| include?(exposure_text, word) }
|
||||
end
|
||||
|
||||
def modified_text(text, spoiler_text)
|
||||
|
@ -14,6 +14,14 @@ class Admin::SensitiveWord
|
|||
|
||||
private
|
||||
|
||||
def include?(text, word)
|
||||
if word.start_with?('?') && word.size >= 2
|
||||
text =~ /#{word[1..]}/i
|
||||
else
|
||||
text.include?(word)
|
||||
end
|
||||
end
|
||||
|
||||
def sensitive_words
|
||||
Setting.sensitive_words || []
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue