* Add: #586 保留中のリモートアカウントからのフォローが飛んできた場合に記録する * 本家に戻す処理を修正 * Fix test * Fix worker link * Fix test * リモートアカウント拒否時に既存のリクエストを削除
This commit is contained in:
parent
1b3c0e3fb7
commit
dfc9f35d71
15 changed files with 262 additions and 31 deletions
7
spec/fabricators/pending_follow_request_fabricator.rb
Normal file
7
spec/fabricators/pending_follow_request_fabricator.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Fabricator(:pending_follow_request) do
|
||||
account { Fabricate.build(:account) }
|
||||
target_account { Fabricate.build(:account, locked: true) }
|
||||
uri 'https://example.com/follow'
|
||||
end
|
|
@ -100,6 +100,10 @@ RSpec.describe ActivityPub::Activity::Follow do
|
|||
expect(sender.requested?(recipient)).to be true
|
||||
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'does not create pending request' do
|
||||
expect(sender.pending_follow_requests.find_by(target_account: recipient)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unlocked account but locked from bot' do
|
||||
|
@ -169,6 +173,49 @@ RSpec.describe ActivityPub::Activity::Follow do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when remote pending account follows unlocked account' do
|
||||
before do
|
||||
sender.update(suspended_at: Time.now.utc, suspension_origin: :local, remote_pending: true)
|
||||
allow(LocalNotificationWorker).to receive(:perform_async).and_return(nil)
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'does not notify' do
|
||||
expect(LocalNotificationWorker).to_not have_received(:perform_async)
|
||||
end
|
||||
|
||||
it 'creates a follow request' do
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
|
||||
follow_request = sender.pending_follow_requests.find_by(target_account: recipient)
|
||||
expect(follow_request).to_not be_nil
|
||||
expect(follow_request.uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when remote pending account follows unlocked account but has already existing request' do
|
||||
before do
|
||||
sender.update(suspended_at: Time.now.utc, suspension_origin: :local, remote_pending: true)
|
||||
Fabricate(:pending_follow_request, account: sender, target_account: recipient, uri: 'old')
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'does not create a follow from sender to recipient' do
|
||||
expect(sender.following?(recipient)).to be false
|
||||
expect(sender.requested?(recipient)).to be false
|
||||
end
|
||||
|
||||
it 'changes follow request uri' do
|
||||
follow_request = sender.pending_follow_requests.find_by(target_account: recipient)
|
||||
expect(follow_request).to_not be_nil
|
||||
expect(follow_request.uri).to eq 'foo'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when domain block reject_straight_follow' do
|
||||
before do
|
||||
Fabricate(:domain_block, domain: 'example.com', reject_straight_follow: true)
|
||||
|
|
55
spec/services/enable_follow_requests_service_spec.rb
Normal file
55
spec/services/enable_follow_requests_service_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe EnableFollowRequestsService, type: :service do
|
||||
subject { described_class.new.call(sender) }
|
||||
|
||||
let(:sender) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') }
|
||||
let(:alice) { Fabricate(:account) }
|
||||
let!(:follow_request) { Fabricate(:pending_follow_request, account: sender, target_account: alice) }
|
||||
|
||||
before do
|
||||
allow(LocalNotificationWorker).to receive(:perform_async).and_return(nil)
|
||||
end
|
||||
|
||||
context 'when has a silent follow request' do
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it 'follows immediately' do
|
||||
follow = Follow.find_by(account: sender, target_account: alice)
|
||||
expect(follow).to_not be_nil
|
||||
expect(LocalNotificationWorker).to have_received(:perform_async).with(alice.id, follow.id, 'Follow', 'follow')
|
||||
|
||||
new_follow_request = FollowRequest.find_by(account: sender, target_account: alice)
|
||||
expect(new_follow_request).to be_nil
|
||||
end
|
||||
|
||||
it 'pending request is removed' do
|
||||
expect { follow_request.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
|
||||
context 'when target_account is locked' do
|
||||
before do
|
||||
alice.update!(locked: true)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'enable a follow request' do
|
||||
new_follow_request = FollowRequest.find_by(account: sender, target_account: alice)
|
||||
|
||||
expect(sender.following?(alice)).to be false
|
||||
|
||||
expect(new_follow_request).to_not be_nil
|
||||
expect(new_follow_request.uri).to eq follow_request.uri
|
||||
expect(LocalNotificationWorker).to have_received(:perform_async).with(alice.id, new_follow_request.id, 'FollowRequest', 'follow_request')
|
||||
end
|
||||
|
||||
it 'pending request is removed' do
|
||||
expect { follow_request.reload }.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue