Fix tootctl self-destruct not sending Delete activities for recently-suspended accounts (#16688)

* Do not block existing users' emails on self-destruct

That is wasteful and unintuitive

* Do not close registrations when running tootctl self-destruct with --dry-run

* Close registrations on self-destruct regardless of known remote accounts

* Fix tootctl self-destruct not sending Deletes for recently-suspended accounts

* Suspend local users even if no remote account is known

* Do not show scary confirmation text if ran with --dry-run
pull/1622/head
Claire 2021-10-14 19:59:28 +02:00 committed by GitHub
parent 216570ad98
commit 959f7fc580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 8 deletions

View File

@ -94,17 +94,22 @@ module Mastodon
exit(1) unless prompt.ask('Type in the domain of the server to confirm:', required: true) == Rails.configuration.x.local_domain exit(1) unless prompt.ask('Type in the domain of the server to confirm:', required: true) == Rails.configuration.x.local_domain
prompt.warn('This operation WILL NOT be reversible. It can also take a long time.') unless options[:dry_run]
prompt.warn('While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.') prompt.warn('This operation WILL NOT be reversible. It can also take a long time.')
prompt.warn('A running Sidekiq process is required. Do not shut it down until queues clear.') prompt.warn('While the data won\'t be erased locally, the server will be in a BROKEN STATE afterwards.')
prompt.warn('A running Sidekiq process is required. Do not shut it down until queues clear.')
exit(1) if prompt.no?('Are you sure you want to proceed?') exit(1) if prompt.no?('Are you sure you want to proceed?')
end
inboxes = Account.inboxes inboxes = Account.inboxes
processed = 0 processed = 0
dry_run = options[:dry_run] ? ' (DRY RUN)' : '' dry_run = options[:dry_run] ? ' (DRY RUN)' : ''
Setting.registrations_mode = 'none' unless options[:dry_run]
if inboxes.empty? if inboxes.empty?
Account.local.without_suspended.in_batches.update_all(suspended_at: Time.now.utc, suspension_origin: :local) unless options[:dry_run]
prompt.ok('It seems like your server has not federated with anything') prompt.ok('It seems like your server has not federated with anything')
prompt.ok('You can shut it down and delete it any time') prompt.ok('You can shut it down and delete it any time')
return return
@ -112,9 +117,7 @@ module Mastodon
prompt.warn('Do NOT interrupt this process...') prompt.warn('Do NOT interrupt this process...')
Setting.registrations_mode = 'none' delete_account = ->(account) do
Account.local.without_suspended.find_each do |account|
payload = ActiveModelSerializers::SerializableResource.new( payload = ActiveModelSerializers::SerializableResource.new(
account, account,
serializer: ActivityPub::DeleteActorSerializer, serializer: ActivityPub::DeleteActorSerializer,
@ -128,12 +131,15 @@ module Mastodon
[json, account.id, inbox_url] [json, account.id, inbox_url]
end end
account.suspend! account.suspend!(block_email: false)
end end
processed += 1 processed += 1
end end
Account.local.without_suspended.find_each { |account| delete_account.call(account) }
Account.local.suspended.joins(:deletion_request).find_each { |account| delete_account.call(account) }
prompt.ok("Queued #{inboxes.size * processed} items into Sidekiq for #{processed} accounts#{dry_run}") prompt.ok("Queued #{inboxes.size * processed} items into Sidekiq for #{processed} accounts#{dry_run}")
prompt.ok('Wait until Sidekiq processes all items, then you can shut everything down and delete the data') prompt.ok('Wait until Sidekiq processes all items, then you can shut everything down and delete the data')
rescue TTY::Reader::InputInterrupt rescue TTY::Reader::InputInterrupt