Purge custom emojis on domain suspension (#37808)
This commit is contained in:
@@ -29,7 +29,12 @@ class BlockDomainService < BaseService
|
|||||||
suspend_accounts!
|
suspend_accounts!
|
||||||
end
|
end
|
||||||
|
|
||||||
DomainClearMediaWorker.perform_async(domain_block.id) if domain_block.reject_media?
|
if domain_block.suspend?
|
||||||
|
# Account images and attachments are already handled by `suspend_accounts!`
|
||||||
|
PurgeCustomEmojiWorker.perform_async(blocked_domain)
|
||||||
|
elsif domain_block.reject_media?
|
||||||
|
DomainClearMediaWorker.perform_async(domain_block.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def silence_accounts!
|
def silence_accounts!
|
||||||
|
|||||||
15
app/workers/purge_custom_emoji_worker.rb
Normal file
15
app/workers/purge_custom_emoji_worker.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class PurgeCustomEmojiWorker
|
||||||
|
include Sidekiq::IterableJob
|
||||||
|
|
||||||
|
def build_enumerator(domain, cursor:)
|
||||||
|
return if domain.blank?
|
||||||
|
|
||||||
|
active_record_batches_enumerator(CustomEmoji.by_domain_and_subdomains(domain), cursor:)
|
||||||
|
end
|
||||||
|
|
||||||
|
def each_iteration(custom_emojis, _domain)
|
||||||
|
AttachmentBatch.new(CustomEmoji, custom_emojis).delete
|
||||||
|
end
|
||||||
|
end
|
||||||
33
spec/workers/purge_custom_emoji_worker_spec.rb
Normal file
33
spec/workers/purge_custom_emoji_worker_spec.rb
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe PurgeCustomEmojiWorker do
|
||||||
|
let(:worker) { described_class.new }
|
||||||
|
|
||||||
|
let(:domain) { 'evil' }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Fabricate(:custom_emoji)
|
||||||
|
Fabricate(:custom_emoji, domain: 'example.com')
|
||||||
|
Fabricate.times(5, :custom_emoji, domain: domain)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#perform' do
|
||||||
|
context 'when domain is nil' do
|
||||||
|
it 'does not delete emojis' do
|
||||||
|
expect { worker.perform(nil) }
|
||||||
|
.to_not(change(CustomEmoji, :count))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when passing a domain' do
|
||||||
|
it 'deletes emojis from this domain only' do
|
||||||
|
expect { worker.perform(domain) }
|
||||||
|
.to change { CustomEmoji.where(domain: domain).count }.to(0)
|
||||||
|
.and not_change { CustomEmoji.local.count }
|
||||||
|
.and(not_change { CustomEmoji.where(domain: 'example.com').count })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user