authorize :instance, :show?
end
+ def destroy
+ authorize :instance, :destroy?
+
+ Admin::DomainPurgeWorker.perform_async(@instance.domain)
+
+ log_action :destroy, @instance
+ redirect_to admin_instances_path, notice: I18n.t('admin.instances.destroyed_msg', domain: @instance.domain)
+ end
+
def clear_delivery_errors
authorize :delivery, :clear_delivery_errors?
link_to truncate(record.text), edit_admin_announcement_path(record.id)
when 'IpBlock'
"#{record.ip}/#{record.ip.prefix} (#{I18n.t("simple_form.labels.ip_block.severities.#{record.severity}")})"
+ when 'Instance'
+ record.domain
end
end
truncate(attributes['text'].is_a?(Array) ? attributes['text'].last : attributes['text'])
when 'IpBlock'
"#{attributes['ip']}/#{attributes['ip'].prefix} (#{I18n.t("simple_form.labels.ip_block.severities.#{attributes['severity']}")})"
+ when 'Instance'
+ attributes['domain']
end
end
end
destroy_domain_allow: { target_type: 'DomainAllow', action: 'destroy' }.freeze,
destroy_domain_block: { target_type: 'DomainBlock', action: 'destroy' }.freeze,
destroy_email_domain_block: { target_type: 'EmailDomainBlock', action: 'destroy' }.freeze,
+ destroy_instance: { target_type: 'Instance', action: 'destroy' }.freeze,
destroy_unavailable_domain: { target_type: 'UnavailableDomain', action: 'destroy' }.freeze,
destroy_status: { target_type: 'Status', action: 'destroy' }.freeze,
disable_2fa_user: { target_type: 'User', action: 'disable' }.freeze,
def show?
admin?
end
+
+ def destroy?
+ admin?
+ end
end
--- /dev/null
+# 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
= link_to t('admin.instances.delivery.stop'), stop_delivery_admin_instance_path(@instance), data: { confirm: t('admin.accounts.are_you_sure'), method: :post }, class: 'button'
- else
= link_to t('admin.instances.delivery.restart'), restart_delivery_admin_instance_path(@instance), data: { confirm: t('admin.accounts.are_you_sure'), method: :post }, class: 'button'
+ - unless @instance.delivery_failure_tracker.available? && @instance.accounts_count > 0
+ = link_to t('admin.instances.purge'), admin_instance_path(@instance), data: { confirm: t('admin.instances.confirm_purge'), method: :delete }, class: 'button'
--- /dev/null
+# frozen_string_literal: true
+
+class Admin::DomainPurgeWorker
+ include Sidekiq::Worker
+
+ def perform(domain)
+ PurgeDomainService.new.call(domain)
+ end
+end
destroy_domain_allow: Delete Domain Allow
destroy_domain_block: Delete Domain Block
destroy_email_domain_block: Delete E-mail Domain Block
+ destroy_instance: Purge Domain
destroy_ip_block: Delete IP rule
destroy_status: Delete Post
destroy_unavailable_domain: Delete Unavailable Domain
destroy_domain_allow_html: "%{name} disallowed federation with domain %{target}"
destroy_domain_block_html: "%{name} unblocked domain %{target}"
destroy_email_domain_block_html: "%{name} unblocked e-mail domain %{target}"
+ destroy_instance_html: "%{name} purged domain %{target}"
destroy_ip_block_html: "%{name} deleted rule for IP %{target}"
destroy_status_html: "%{name} removed post by %{target}"
destroy_unavailable_domain_html: "%{name} resumed delivery to domain %{target}"
back_to_limited: Limited
back_to_warning: Warning
by_domain: Domain
+ confirm_purge: Are you sure you want to permanently delete data from this domain?
delivery:
all: All
clear: Clear delivery errors
delivery_available: Delivery is available
delivery_error_days: Delivery error days
delivery_error_hint: If delivery is not possible for %{count} days, it will be automatically marked as undeliverable.
+ destroyed_msg: Data from %{domain} is now queued for imminent deletion.
empty: No domains found.
known_accounts:
one: "%{count} known account"
title: Moderation
private_comment: Private comment
public_comment: Public comment
+ purge: Purge
title: Federation
total_blocked_by_us: Blocked by us
total_followed_by_them: Followed by them
end
end
- resources :instances, only: [:index, :show], constraints: { id: /[^\/]+/ } do
+ resources :instances, only: [:index, :show, :destroy], constraints: { id: /[^\/]+/ } do
member do
post :clear_delivery_errors
post :restart_delivery
RSpec.describe Admin::InstancesController, type: :controller do
render_views
+ let(:current_user) { Fabricate(:user, admin: true) }
+
+ let!(:account) { Fabricate(:account, domain: 'popular') }
+ let!(:account2) { Fabricate(:account, domain: 'popular') }
+ let!(:account3) { Fabricate(:account, domain: 'less.popular') }
+
before do
- sign_in Fabricate(:user, admin: true), scope: :user
+ sign_in current_user, scope: :user
end
describe 'GET #index' do
end
it 'renders instances' do
- Fabricate(:account, domain: 'popular')
- Fabricate(:account, domain: 'popular')
- Fabricate(:account, domain: 'less.popular')
-
get :index, params: { page: 2 }
instances = assigns(:instances).to_a
expect(response).to have_http_status(200)
end
end
+
+ describe 'DELETE #destroy' do
+ subject { delete :destroy, params: { id: Instance.first.id } }
+
+ let(:current_user) { Fabricate(:user, admin: admin) }
+ let(:account) { Fabricate(:account) }
+
+ context 'when user is admin' do
+ let(:admin) { true }
+
+ it 'succeeds in purging instance' do
+ is_expected.to redirect_to admin_instances_path
+ end
+ end
+
+ context 'when user is not admin' do
+ let(:admin) { false }
+
+ it 'fails to purge instance' do
+ is_expected.to have_http_status :forbidden
+ end
+ end
+ end
end
let(:admin) { Fabricate(:user, admin: true).account }
let(:john) { Fabricate(:user).account }
- permissions :index? do
+ permissions :index?, :show?, :destroy? do
context 'admin' do
it 'permits' do
expect(subject).to permit(admin, Instance)
--- /dev/null
+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
--- /dev/null
+# 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