Fix possible race conditions when suspending/unsuspending accounts (#22363)

* Fix possible race conditions when suspending/unsuspending accounts

* Fix tests

Tests were assuming SuspensionWorker and UnsuspensionWorker would do the
suspending/unsuspending themselves, but this has changed.
This commit is contained in:
Claire 2023-01-05 13:47:21 +01:00 committed by GitHub
parent 8683a082dd
commit 18fb01ef7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 19 deletions

View file

@ -3,10 +3,13 @@
class SuspendAccountService < BaseService
include Payloadable
# Carry out the suspension of a recently-suspended account
# @param [Account] account Account to suspend
def call(account)
return unless account.suspended?
@account = account
suspend!
reject_remote_follows!
distribute_update_actor!
unmerge_from_home_timelines!
@ -16,10 +19,6 @@ class SuspendAccountService < BaseService
private
def suspend!
@account.suspend! unless @account.suspended?
end
def reject_remote_follows!
return if @account.local? || !@account.activitypub?

View file

@ -2,10 +2,12 @@
class UnsuspendAccountService < BaseService
include Payloadable
# Restores a recently-unsuspended account
# @param [Account] account Account to restore
def call(account)
@account = account
unsuspend!
refresh_remote_account!
return if @account.nil? || @account.suspended?
@ -18,10 +20,6 @@ class UnsuspendAccountService < BaseService
private
def unsuspend!
@account.unsuspend! if @account.suspended?
end
def refresh_remote_account!
return if @account.local?