Change: #648 センシティブワードの入力フォーム (#653)

* Change: #648 センシティブワードの入力フォーム

* Wip: 行の追加削除

* Wip: 設定の保存、マイグレーション

* 不要な処理を削除

* マイグレーションコード調整
This commit is contained in:
KMY(雪あすか) 2024-03-19 08:18:34 +09:00 committed by GitHub
parent f509bd4fc3
commit ed246f0d03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 377 additions and 61 deletions

View file

@ -0,0 +1,5 @@
# frozen_string_literal: true
Fabricator(:sensitive_word) do
keyword { sequence(:keyword) { |i| "keyword_#{i}" } }
end

View file

@ -2071,7 +2071,8 @@ RSpec.describe ActivityPub::Activity::Create do
end
before do
Form::AdminSettings.new(sensitive_words_all: sensitive_words_all, sensitive_words: 'ipsum').save
Fabricate(:sensitive_word, keyword: sensitive_words_all, remote: true, spoiler: false) if sensitive_words_all.present?
Fabricate(:sensitive_word, keyword: 'ipsum')
subject.perform
end

View file

@ -0,0 +1,75 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::SensitiveWord do
describe '#sensitive?' do
subject { described_class.sensitive?(text, spoiler_text, local: local) }
let(:text) { 'This is a ohagi.' }
let(:spoiler_text) { '' }
let(:local) { true }
context 'when a local post' do
it 'local word hits' do
Fabricate(:sensitive_word, keyword: 'ohagi', remote: false)
expect(subject).to be true
end
it 'remote word hits' do
Fabricate(:sensitive_word, keyword: 'ohagi', remote: true)
expect(subject).to be true
end
end
context 'when a remote post' do
let(:local) { false }
it 'local word does not hit' do
Fabricate(:sensitive_word, keyword: 'ohagi', remote: false)
expect(subject).to be false
end
it 'remote word hits' do
Fabricate(:sensitive_word, keyword: 'ohagi', remote: true)
expect(subject).to be true
end
end
context 'when using regexp' do
it 'regexp hits with enable' do
Fabricate(:sensitive_word, keyword: 'oha[ghi]i', regexp: true)
expect(subject).to be true
end
it 'regexp does not hit without enable' do
Fabricate(:sensitive_word, keyword: 'oha[ghi]i', regexp: false)
expect(subject).to be false
end
end
context 'when spoiler text is set' do
let(:spoiler_text) { 'amy' }
it 'sensitive word in content is escaped' do
Fabricate(:sensitive_word, keyword: 'ohagi', spoiler: false)
expect(subject).to be false
end
it 'sensitive word in content is escaped even if spoiler is true' do
Fabricate(:sensitive_word, keyword: 'ohagi', spoiler: true)
expect(subject).to be false
end
it 'non-spoiler word does not hit' do
Fabricate(:sensitive_word, keyword: 'amy', spoiler: false)
expect(subject).to be false
end
it 'spoiler word hits' do
Fabricate(:sensitive_word, keyword: 'amy', spoiler: true)
expect(subject).to be true
end
end
end
end

View file

@ -758,7 +758,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
let(:content) { 'ng word aiueo' }
it 'update status' do
Form::AdminSettings.new(sensitive_words_all: 'test').save
Fabricate(:sensitive_word, keyword: 'test', remote: true, spoiler: false)
subject.call(status, json, json)
expect(status.reload.text).to eq content
@ -770,7 +770,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
let(:content) { 'ng word test' }
it 'update status' do
Form::AdminSettings.new(sensitive_words_all: 'test').save
Fabricate(:sensitive_word, keyword: 'test', remote: true, spoiler: false)
subject.call(status, json, json)
expect(status.reload.text).to eq content