Add: #87 フォロワーのみに購読を許可する設定 (#239)

* Wip: マイグレーション、設定など一式

* Fix test

* Fix test

* Fix: マスター用の設定を他サーバーに送信しないよう修正

* DTL、外部サーバーの情報受け入れのテストを追加

* スペルミスを修正

* Web画面に設定項目追加

* 既存の`master_settings`を上書きしないよう修正
This commit is contained in:
KMY(雪あすか) 2023-11-08 17:51:36 +09:00 committed by GitHub
parent a7dec3c59b
commit 76f2f2ed0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 284 additions and 52 deletions

View file

@ -156,6 +156,71 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
end
end
context 'with subscription policy' do
subject { described_class.new.call('alice', 'example.com', payload) }
let(:subscribable_by) { 'https://www.w3.org/ns/activitystreams#Public' }
let(:sender_bio) { '' }
let(:payload) do
{
id: 'https://foo.test',
type: 'Actor',
inbox: 'https://foo.test/inbox',
followers: 'https://example.com/followers',
subscribableBy: subscribable_by,
summary: sender_bio,
actor_type: 'Person',
}.with_indifferent_access
end
before do
stub_request(:get, 'https://example.com/.well-known/nodeinfo').to_return(body: '{}')
stub_request(:get, 'https://example.com/followers').to_return(body: '[]')
end
context 'when public' do
it 'subscription policy is allow' do
expect(subject.subscription_policy.to_s).to eq 'allow'
end
end
context 'when private' do
let(:subscribable_by) { 'https://example.com/followers' }
it 'subscription policy is followers_only' do
expect(subject.subscription_policy.to_s).to eq 'followers_only'
end
end
context 'when empty' do
let(:subscribable_by) { '' }
it 'subscription policy is block' do
expect(subject.subscription_policy.to_s).to eq 'block'
end
end
context 'when default value' do
let(:subscribable_by) { nil }
it 'subscription policy is allow' do
expect(subject.subscription_policy.to_s).to eq 'allow'
end
end
context 'with bio' do
let(:subscribable_by) { nil }
context 'with no-subscribe' do
let(:sender_bio) { '[subscribable:no]' }
it 'subscription policy is block' do
expect(subject.subscription_policy.to_s).to eq 'block'
end
end
end
end
context 'with property values' do
let(:payload) do
{

View file

@ -10,10 +10,10 @@ RSpec.describe FanOutOnWriteService, type: :service do
let(:last_active_at) { Time.now.utc }
let(:visibility) { 'public' }
let(:searchability) { 'public' }
let(:dissubscribable) { false }
let(:subscription_policy) { :allow }
let(:status) { Fabricate(:status, account: alice, visibility: visibility, searchability: searchability, text: 'Hello @bob #hoge') }
let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { dissubscribable: dissubscribable }).account }
let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { master_settings: { subscription_policy: subscription_policy } }).account }
let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account }
let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at).account }
let!(:ohagi) { Fabricate(:user, current_sign_in_at: last_active_at).account }
@ -64,6 +64,13 @@ RSpec.describe FanOutOnWriteService, type: :service do
antenna
end
def antenna_with_tag(owner, target_tag, **options)
antenna = Fabricate(:antenna, account: owner, any_tags: false, **options)
tag = Tag.find_or_create_by_names([target_tag])[0]
Fabricate(:antenna_tag, antenna: antenna, tag: tag)
antenna
end
def antenna_with_options(owner, **options)
Fabricate(:antenna, account: owner, **options)
end
@ -123,13 +130,69 @@ RSpec.describe FanOutOnWriteService, type: :service do
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
context 'when dissubscribable is true' do
let(:dissubscribable) { true }
context 'when subscription is blocked' do
let(:subscription_policy) { :block }
it 'is not added to the antenna feed' do
expect(antenna_feed_of(antenna)).to_not include status.id
end
end
context 'when subscription is allowed followers only' do
let(:subscription_policy) { :followers_only }
let!(:antenna) { antenna_with_account(ohagi, alice) }
it 'is not added to the antenna feed' do
expect(antenna_feed_of(antenna)).to_not include status.id
end
context 'with following' do
let!(:antenna) { antenna_with_account(bob, alice) }
it 'is added to the antenna feed' do
expect(antenna_feed_of(antenna)).to include status.id
end
end
end
context 'when dtl post' do
let!(:antenna) { antenna_with_tag(bob, 'hoge') }
around do |example|
ClimateControl.modify DTL_ENABLED: 'true', DTL_TAG: 'hoge' do
example.run
end
end
context 'with listening tag' do
it 'is added to the antenna feed' do
expect(antenna_feed_of(antenna)).to include status.id
end
end
context 'with listening tag but sender is limiting subscription' do
let(:subscription_policy) { :block }
it 'does not add to the antenna feed' do
expect(antenna_feed_of(antenna)).to_not include status.id
end
end
context 'with listening tag but sender is limiting subscription but permit dtl only' do
let(:subscription_policy) { :block }
let(:custom_before) { true }
before do
alice.user.settings['dtl_force_subscribable'] = true
alice.user.save!
subject.call(status)
end
it 'is added to the antenna feed' do
expect(antenna_feed_of(antenna)).to include status.id
end
end
end
end
context 'with STL antenna' do
@ -141,8 +204,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
context 'when dissubscribable is true' do
let(:dissubscribable) { true }
context 'when subscription is blocked' do
let(:subscription_policy) { :block }
it 'is added to the antenna feed' do
expect(antenna_feed_of(antenna)).to include status.id
@ -168,8 +231,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
context 'when dissubscribable is true' do
let(:dissubscribable) { true }
context 'when subscription is blocked' do
let(:subscription_policy) { :block }
it 'is added to the antenna feed' do
expect(antenna_feed_of(antenna)).to include status.id
@ -370,8 +433,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
context 'when dissubscribable is true' do
let(:dissubscribable) { true }
context 'when subscription is blocked' do
let(:subscription_policy) { :block }
it 'is not added to the antenna feed' do
expect(antenna_feed_of(antenna)).to_not include status.id
@ -388,8 +451,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
context 'when dissubscribable is true' do
let(:dissubscribable) { true }
context 'when subscription is blocked' do
let(:subscription_policy) { :block }
it 'is added to the antenna feed' do
expect(antenna_feed_of(antenna)).to include status.id
@ -415,8 +478,8 @@ RSpec.describe FanOutOnWriteService, type: :service do
expect(antenna_feed_of(empty_antenna)).to_not include status.id
end
context 'when dissubscribable is true' do
let(:dissubscribable) { true }
context 'when subscription is blocked' do
let(:subscription_policy) { :block }
it 'is added to the antenna feed' do
expect(antenna_feed_of(antenna)).to include status.id