* Change: #648 センシティブワードの入力フォーム * Wip: 行の追加削除 * Wip: 設定の保存、マイグレーション * 不要な処理を削除 * マイグレーションコード調整
This commit is contained in:
parent
f509bd4fc3
commit
ed246f0d03
17 changed files with 377 additions and 61 deletions
|
@ -5,12 +5,12 @@ class Admin::SensitiveWord
|
|||
def sensitive?(text, spoiler_text, local: true)
|
||||
exposure_text = spoiler_text.presence || text
|
||||
|
||||
sensitive = (spoiler_text.blank? && sensitive_words_all.any? { |word| include?(text, word) }) ||
|
||||
sensitive_words_all_for_full.any? { |word| include?(exposure_text, word) }
|
||||
return sensitive if sensitive || !local
|
||||
sensitive_words = ::SensitiveWord.caches
|
||||
sensitive_words.select!(&:remote) unless local
|
||||
|
||||
(spoiler_text.blank? && sensitive_words.any? { |word| include?(text, word) }) ||
|
||||
sensitive_words_for_full.any? { |word| include?(exposure_text, word) }
|
||||
return sensitive_words.filter(&:spoiler).any? { |word| include?(spoiler_text, word) } if spoiler_text.present?
|
||||
|
||||
sensitive_words.any? { |word| include?(exposure_text, word) }
|
||||
end
|
||||
|
||||
def modified_text(text, spoiler_text)
|
||||
|
@ -24,27 +24,11 @@ class Admin::SensitiveWord
|
|||
private
|
||||
|
||||
def include?(text, word)
|
||||
if word.start_with?('?') && word.size >= 2
|
||||
text =~ /#{word[1..]}/i
|
||||
if word.regexp
|
||||
text =~ /#{word.keyword}/
|
||||
else
|
||||
text.include?(word)
|
||||
text.include?(word.keyword)
|
||||
end
|
||||
end
|
||||
|
||||
def sensitive_words
|
||||
Setting.sensitive_words || []
|
||||
end
|
||||
|
||||
def sensitive_words_for_full
|
||||
Setting.sensitive_words_for_full || []
|
||||
end
|
||||
|
||||
def sensitive_words_all
|
||||
Setting.sensitive_words_all || []
|
||||
end
|
||||
|
||||
def sensitive_words_all_for_full
|
||||
Setting.sensitive_words_all_for_full || []
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue