]> cat aescling's git repositories - mastodon.git/commitdiff
Fix BootstrapTimelineService crashing when bootstrapped accounts are invalid (#12037)
authorThibG <thib@sitedethib.com>
Tue, 1 Oct 2019 13:10:00 +0000 (15:10 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 1 Oct 2019 13:10:00 +0000 (15:10 +0200)
* Add test to handle suspended and missing users in BootstrapTimelineService

* Fix BootstrapTimelineService crashing when bootstrapped accounts are invalid

app/services/bootstrap_timeline_service.rb
spec/services/bootstrap_timeline_service_spec.rb

index db2c83e5d1ced84ab75a70fdd61cd257ec498bb8..c489601c155b72ce40d07fdb6aad1ff544d61945 100644 (file)
@@ -17,7 +17,11 @@ class BootstrapTimelineService < BaseService
 
   def autofollow_bootstrap_timeline_accounts!
     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
 
@@ -40,7 +44,9 @@ class BootstrapTimelineService < BaseService
 
   def local_unlocked_accounts(usernames)
     Account.local
+           .without_suspended
            .where(username: usernames)
            .where(locked: false)
+           .where(moved_to_account_id: nil)
   end
 end
index a765de79127baf61314f396a6af3679066a48c98..a28d2407c1cf7ca25b778c3a6558c3925d1e7a70 100644 (file)
@@ -22,9 +22,10 @@ RSpec.describe BootstrapTimelineService, type: :service do
     context 'when setting is set' do
       let!(:alice) { Fabricate(:account, username: 'alice') }
       let!(:bob)   { Fabricate(:account, username: 'bob') }
+      let!(:eve)   { Fabricate(:account, username: 'eve', suspended: true) }
 
       before do
-        Setting.bootstrap_timeline_accounts = 'alice, bob'
+        Setting.bootstrap_timeline_accounts = 'alice, @bob, eve, unknown'
         subject.call(source_account)
       end
 
@@ -32,6 +33,10 @@ RSpec.describe BootstrapTimelineService, type: :service do
         expect(source_account.following?(alice)).to be true
         expect(source_account.following?(bob)).to be true
       end
+
+      it 'does not follow suspended account' do
+        expect(source_account.following?(eve)).to be false
+      end
     end
   end
 end