|
|
@ -15,7 +15,6 @@ class SuspendAccountService < BaseService
|
|
|
|
favourites
|
|
|
|
favourites
|
|
|
|
follow_requests
|
|
|
|
follow_requests
|
|
|
|
list_accounts
|
|
|
|
list_accounts
|
|
|
|
media_attachments
|
|
|
|
|
|
|
|
mute_relationships
|
|
|
|
mute_relationships
|
|
|
|
muted_by_relationships
|
|
|
|
muted_by_relationships
|
|
|
|
notifications
|
|
|
|
notifications
|
|
|
@ -32,14 +31,26 @@ class SuspendAccountService < BaseService
|
|
|
|
targeted_reports
|
|
|
|
targeted_reports
|
|
|
|
).freeze
|
|
|
|
).freeze
|
|
|
|
|
|
|
|
|
|
|
|
# Suspend an account and remove as much of its data as possible
|
|
|
|
# Suspend or remove an account and remove as much of its data
|
|
|
|
|
|
|
|
# as possible. If it's a local account and it has not been confirmed
|
|
|
|
|
|
|
|
# or never been approved, then side effects are skipped and both
|
|
|
|
|
|
|
|
# the user and account records are removed fully. Otherwise,
|
|
|
|
|
|
|
|
# it is controlled by options.
|
|
|
|
# @param [Account]
|
|
|
|
# @param [Account]
|
|
|
|
# @param [Hash] options
|
|
|
|
# @param [Hash] options
|
|
|
|
# @option [Boolean] :including_user Remove the user record as well
|
|
|
|
# @option [Boolean] :reserve_email Keep user record. Only applicable for local accounts
|
|
|
|
# @option [Boolean] :destroy Remove the account record instead of suspending
|
|
|
|
# @option [Boolean] :reserve_username Keep account record
|
|
|
|
|
|
|
|
# @option [Boolean] :skip_side_effects Side effects are ActivityPub and streaming API payloads
|
|
|
|
|
|
|
|
# @option [Time] :suspended_at Only applicable when :reserve_username is true
|
|
|
|
def call(account, **options)
|
|
|
|
def call(account, **options)
|
|
|
|
@account = account
|
|
|
|
@account = account
|
|
|
|
@options = options
|
|
|
|
@options = { reserve_username: true, reserve_email: true }.merge(options)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if @account.local? && @account.user_unconfirmed_or_pending?
|
|
|
|
|
|
|
|
@options[:reserve_email] = false
|
|
|
|
|
|
|
|
@options[:reserve_username] = false
|
|
|
|
|
|
|
|
@options[:skip_side_effects] = true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
reject_follows!
|
|
|
|
reject_follows!
|
|
|
|
purge_user!
|
|
|
|
purge_user!
|
|
|
@ -60,27 +71,39 @@ class SuspendAccountService < BaseService
|
|
|
|
def purge_user!
|
|
|
|
def purge_user!
|
|
|
|
return if !@account.local? || @account.user.nil?
|
|
|
|
return if !@account.local? || @account.user.nil?
|
|
|
|
|
|
|
|
|
|
|
|
if @options[:including_user]
|
|
|
|
if @options[:reserve_email]
|
|
|
|
@options[:destroy] = true if !@account.user_confirmed? || @account.user_pending?
|
|
|
|
|
|
|
|
@account.user.destroy
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@account.user.disable!
|
|
|
|
@account.user.disable!
|
|
|
|
@account.user.invites.where(uses: 0).destroy_all
|
|
|
|
@account.user.invites.where(uses: 0).destroy_all
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
@account.user.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def purge_content!
|
|
|
|
def purge_content!
|
|
|
|
distribute_delete_actor! if @account.local? && !@options[:skip_distribution]
|
|
|
|
distribute_delete_actor! if @account.local? && !@options[:skip_side_effects]
|
|
|
|
|
|
|
|
|
|
|
|
@account.statuses.reorder(nil).find_in_batches do |statuses|
|
|
|
|
@account.statuses.reorder(nil).find_in_batches do |statuses|
|
|
|
|
BatchedRemoveStatusService.new.call(statuses, skip_side_effects: @options[:destroy])
|
|
|
|
statuses.reject! { |status| reported_status_ids.include?(status.id) } if @options[:reserve_username]
|
|
|
|
|
|
|
|
BatchedRemoveStatusService.new.call(statuses, skip_side_effects: @options[:skip_side_effects])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@account.media_attachments.reorder(nil).find_each do |media_attachment|
|
|
|
|
|
|
|
|
next if @options[:reserve_username] && reported_status_ids.include?(media_attachment.status_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
media_attachment.destroy
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@account.polls.reorder(nil).find_each do |poll|
|
|
|
|
|
|
|
|
next if @options[:reserve_username] && reported_status_ids.include?(poll.status_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
poll.destroy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
associations_for_destruction.each do |association_name|
|
|
|
|
associations_for_destruction.each do |association_name|
|
|
|
|
destroy_all(@account.public_send(association_name))
|
|
|
|
destroy_all(@account.public_send(association_name))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
@account.destroy if @options[:destroy]
|
|
|
|
@account.destroy unless @options[:reserve_username]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def purge_profile!
|
|
|
|
def purge_profile!
|
|
|
@ -88,11 +111,13 @@ class SuspendAccountService < BaseService
|
|
|
|
# there is no point wasting time updating
|
|
|
|
# there is no point wasting time updating
|
|
|
|
# its values first
|
|
|
|
# its values first
|
|
|
|
|
|
|
|
|
|
|
|
return if @options[:destroy]
|
|
|
|
return unless @options[:reserve_username]
|
|
|
|
|
|
|
|
|
|
|
|
@account.silenced_at = nil
|
|
|
|
@account.silenced_at = nil
|
|
|
|
@account.suspended_at = @options[:suspended_at] || Time.now.utc
|
|
|
|
@account.suspended_at = @options[:suspended_at] || Time.now.utc
|
|
|
|
@account.locked = false
|
|
|
|
@account.locked = false
|
|
|
|
|
|
|
|
@account.memorial = false
|
|
|
|
|
|
|
|
@account.discoverable = false
|
|
|
|
@account.display_name = ''
|
|
|
|
@account.display_name = ''
|
|
|
|
@account.note = ''
|
|
|
|
@account.note = ''
|
|
|
|
@account.fields = []
|
|
|
|
@account.fields = []
|
|
|
@ -100,6 +125,7 @@ class SuspendAccountService < BaseService
|
|
|
|
@account.followers_count = 0
|
|
|
|
@account.followers_count = 0
|
|
|
|
@account.following_count = 0
|
|
|
|
@account.following_count = 0
|
|
|
|
@account.moved_to_account = nil
|
|
|
|
@account.moved_to_account = nil
|
|
|
|
|
|
|
|
@account.trust_level = :untrusted
|
|
|
|
@account.avatar.destroy
|
|
|
|
@account.avatar.destroy
|
|
|
|
@account.header.destroy
|
|
|
|
@account.header.destroy
|
|
|
|
@account.save!
|
|
|
|
@account.save!
|
|
|
@ -135,11 +161,15 @@ class SuspendAccountService < BaseService
|
|
|
|
Account.inboxes - delivery_inboxes
|
|
|
|
Account.inboxes - delivery_inboxes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reported_status_ids
|
|
|
|
|
|
|
|
@reported_status_ids ||= Report.where(target_account: @account).unresolved.pluck(:status_ids).flatten.uniq
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def associations_for_destruction
|
|
|
|
def associations_for_destruction
|
|
|
|
if @options[:destroy]
|
|
|
|
if @options[:reserve_username]
|
|
|
|
ASSOCIATIONS_ON_SUSPEND + ASSOCIATIONS_ON_DESTROY
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
ASSOCIATIONS_ON_SUSPEND
|
|
|
|
ASSOCIATIONS_ON_SUSPEND
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
ASSOCIATIONS_ON_SUSPEND + ASSOCIATIONS_ON_DESTROY
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|