Fix BootstrapTimelineService crashing when bootstrapped accounts are invalid (#12037)

* Add test to handle suspended and missing users in BootstrapTimelineService

* Fix BootstrapTimelineService crashing when bootstrapped accounts are invalid
This commit is contained in:
ThibG 2019-10-01 15:10:00 +02:00 committed by Eugen Rochko
parent 541269f8bc
commit 3a4d994c40
2 changed files with 13 additions and 2 deletions

View file

@ -17,7 +17,11 @@ class BootstrapTimelineService < BaseService
def autofollow_bootstrap_timeline_accounts! def autofollow_bootstrap_timeline_accounts!
bootstrap_timeline_accounts.each do |target_account| bootstrap_timeline_accounts.each do |target_account|
FollowService.new.call(@source_account, target_account) begin
FollowService.new.call(@source_account, target_account)
rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError
nil
end
end end
end end
@ -40,7 +44,9 @@ class BootstrapTimelineService < BaseService
def local_unlocked_accounts(usernames) def local_unlocked_accounts(usernames)
Account.local Account.local
.without_suspended
.where(username: usernames) .where(username: usernames)
.where(locked: false) .where(locked: false)
.where(moved_to_account_id: nil)
end end
end end

View file

@ -22,9 +22,10 @@ RSpec.describe BootstrapTimelineService, type: :service do
context 'when setting is set' do context 'when setting is set' do
let!(:alice) { Fabricate(:account, username: 'alice') } let!(:alice) { Fabricate(:account, username: 'alice') }
let!(:bob) { Fabricate(:account, username: 'bob') } let!(:bob) { Fabricate(:account, username: 'bob') }
let!(:eve) { Fabricate(:account, username: 'eve', suspended: true) }
before do before do
Setting.bootstrap_timeline_accounts = 'alice, bob' Setting.bootstrap_timeline_accounts = 'alice, @bob, eve, unknown'
subject.call(source_account) subject.call(source_account)
end end
@ -32,6 +33,10 @@ RSpec.describe BootstrapTimelineService, type: :service do
expect(source_account.following?(alice)).to be true expect(source_account.following?(alice)).to be true
expect(source_account.following?(bob)).to be true expect(source_account.following?(bob)).to be true
end end
it 'does not follow suspended account' do
expect(source_account.following?(eve)).to be false
end
end end
end end
end end