Add: #605 リモート投稿に適用するセンシティブワード設定 (#612)

This commit is contained in:
KMY(雪あすか) 2024-02-27 10:14:42 +09:00 committed by GitHub
parent 7d96d5828e
commit 9dd11117db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 149 additions and 11 deletions

View file

@ -2087,6 +2087,45 @@ RSpec.describe ActivityPub::Activity::Create do
end
end
context 'when sensitive word is set' do
let(:custom_before) { true }
let(:content) { 'Lorem ipsum' }
let(:sensitive_words_all) { 'hello' }
let(:object_json) do
{
id: [ActivityPub::TagManager.instance.uri_for(sender), '#bar'].join,
type: 'Note',
content: content,
to: 'https://www.w3.org/ns/activitystreams#Public',
}
end
before do
Form::AdminSettings.new(sensitive_words_all: sensitive_words_all, sensitive_words: 'ipsum').save
subject.perform
end
context 'when not contains sensitive words' do
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.spoiler_text).to eq ''
end
end
context 'when contains sensitive words' do
let(:content) { 'hello world' }
it 'creates status' do
status = sender.statuses.first
expect(status).to_not be_nil
expect(status.spoiler_text).to_not eq ''
end
end
end
context 'when hashtags limit is set' do
let(:post_hash_tags_max) { 2 }
let(:custom_before) { true }

View file

@ -682,7 +682,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end
end
context 'when ng rule is existing' do
describe 'ng rule is set' do
context 'when ng rule is match' do
before do
Fabricate(:ng_rule, account_domain: 'example.com', status_text: 'universe')
@ -707,5 +707,42 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do
end
end
end
describe 'sensitive word is set' do
let(:payload) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Note',
content: content,
updated: '2021-09-08T22:39:25Z',
tag: json_tags,
}
end
context 'when hit sensitive words' do
let(:content) { 'ng word aiueo' }
it 'update status' do
Form::AdminSettings.new(sensitive_words_all: 'test').save
subject.call(status, json, json)
expect(status.reload.text).to eq content
expect(status.spoiler_text).to eq ''
end
end
context 'when not hit sensitive words' do
let(:content) { 'ng word test' }
it 'update status' do
Form::AdminSettings.new(sensitive_words_all: 'test').save
subject.call(status, json, json)
expect(status.reload.text).to eq content
expect(status.spoiler_text).to_not eq ''
end
end
end
end
end