mirror of
https://github.com/lunaisnotaboy/mastodon.git
synced 2024-11-18 21:03:27 +00:00
89f40b6c3e
* Split media cleanup from reject-media domain blocks to its own service * Slightly improve ClearDomainMediaService error handling * Lower DomainClearMediaWorker to lowest-priority queue * Do not catch ActiveRecord::RecordNotFound in domain block workers * Fix DomainBlockWorker spec labels * Add some specs * Change domain blocks to immediately mark accounts as suspended Rather than doing so sequentially, account after account, while cleaning their data. This doesn't change much about the time the block takes to complete, but it immediately prevents interaction with the blocked domain, while up to now, it would only be guaranteed when the process ends.
51 lines
1.6 KiB
Ruby
51 lines
1.6 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class BlockDomainService < BaseService
|
|
attr_reader :domain_block
|
|
|
|
def call(domain_block, update = false)
|
|
@domain_block = domain_block
|
|
process_domain_block!
|
|
process_retroactive_updates! if update
|
|
end
|
|
|
|
private
|
|
|
|
def process_retroactive_updates!
|
|
# If the domain block severity has been changed, undo the appropriate limitations
|
|
scope = Account.by_domain_and_subdomains(domain_block.domain)
|
|
|
|
scope.where(silenced_at: domain_block.created_at).in_batches.update_all(silenced_at: nil) unless domain_block.silence?
|
|
scope.where(suspended_at: domain_block.created_at).in_batches.update_all(suspended_at: nil) unless domain_block.suspend?
|
|
end
|
|
|
|
def process_domain_block!
|
|
if domain_block.silence?
|
|
silence_accounts!
|
|
elsif domain_block.suspend?
|
|
suspend_accounts!
|
|
end
|
|
|
|
DomainClearMediaWorker.perform_async(domain_block.id) if domain_block.reject_media?
|
|
end
|
|
|
|
def silence_accounts!
|
|
blocked_domain_accounts.without_silenced.in_batches.update_all(silenced_at: @domain_block.created_at)
|
|
end
|
|
|
|
def suspend_accounts!
|
|
blocked_domain_accounts.without_suspended.in_batches.update_all(suspended_at: @domain_block.created_at)
|
|
blocked_domain_accounts.where(suspended_at: @domain_block.created_at).reorder(nil).find_each do |account|
|
|
SuspendAccountService.new.call(account, reserve_username: true, suspended_at: @domain_block.created_at)
|
|
end
|
|
end
|
|
|
|
def blocked_domain
|
|
domain_block.domain
|
|
end
|
|
|
|
def blocked_domain_accounts
|
|
Account.by_domain_and_subdomains(blocked_domain)
|
|
end
|
|
end
|