Add ability to purge undeliverable domains from admin interface (#16686)
* Add ability to purge undeliverable domains from admin interface * Add teststh-downstream
parent
36347cf494
commit
44c8b6ff2f
@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class PurgeDomainService < BaseService
|
||||
def call(domain)
|
||||
Account.remote.where(domain: domain).reorder(nil).find_each do |account|
|
||||
DeleteAccountService.new.call(account, reserve_username: false, skip_side_effects: true)
|
||||
end
|
||||
Instance.refresh
|
||||
end
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::DomainPurgeWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(domain)
|
||||
PurgeDomainService.new.call(domain)
|
||||
end
|
||||
end
|
@ -0,0 +1,27 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe PurgeDomainService, type: :service do
|
||||
let!(:old_account) { Fabricate(:account, domain: 'obsolete.org') }
|
||||
let!(:old_status1) { Fabricate(:status, account: old_account) }
|
||||
let!(:old_status2) { Fabricate(:status, account: old_account) }
|
||||
let!(:old_attachment) { Fabricate(:media_attachment, account: old_account, status: old_status2, file: attachment_fixture('attachment.jpg')) }
|
||||
|
||||
subject { PurgeDomainService.new }
|
||||
|
||||
describe 'for a suspension' do
|
||||
before do
|
||||
subject.call('obsolete.org')
|
||||
end
|
||||
|
||||
it 'removes the remote accounts\'s statuses and media attachments' do
|
||||
expect { old_account.reload }.to raise_exception ActiveRecord::RecordNotFound
|
||||
expect { old_status1.reload }.to raise_exception ActiveRecord::RecordNotFound
|
||||
expect { old_status2.reload }.to raise_exception ActiveRecord::RecordNotFound
|
||||
expect { old_attachment.reload }.to raise_exception ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
it 'refreshes instances view' do
|
||||
expect(Instance.where(domain: 'obsolete.org').exists?).to be false
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Admin::DomainPurgeWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
describe 'perform' do
|
||||
it 'calls domain purge service for relevant domain block' do
|
||||
service = double(call: nil)
|
||||
allow(PurgeDomainService).to receive(:new).and_return(service)
|
||||
result = subject.perform('example.com')
|
||||
|
||||
expect(result).to be_nil
|
||||
expect(service).to have_received(:call).with('example.com')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue