2020-09-15 22:37:58 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UnsuspendAccountService < BaseService
|
2021-08-20 16:39:37 +10:00
|
|
|
include Payloadable
|
2023-01-05 23:47:21 +11:00
|
|
|
|
|
|
|
# Restores a recently-unsuspended account
|
|
|
|
# @param [Account] account Account to restore
|
2020-09-15 22:37:58 +10:00
|
|
|
def call(account)
|
|
|
|
@account = account
|
|
|
|
|
2020-11-08 10:28:39 +11:00
|
|
|
refresh_remote_account!
|
|
|
|
|
2021-08-20 16:40:33 +10:00
|
|
|
return if @account.nil? || @account.suspended?
|
2020-11-08 10:28:39 +11:00
|
|
|
|
2020-09-15 22:37:58 +10:00
|
|
|
merge_into_home_timelines!
|
|
|
|
merge_into_list_timelines!
|
|
|
|
publish_media_attachments!
|
2021-04-17 22:55:46 +10:00
|
|
|
distribute_update_actor!
|
2020-09-15 22:37:58 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-11-08 10:28:39 +11:00
|
|
|
def refresh_remote_account!
|
|
|
|
return if @account.local?
|
|
|
|
|
|
|
|
# While we had the remote account suspended, it could be that
|
|
|
|
# it got suspended on its origin, too. So, we need to refresh
|
|
|
|
# it straight away so it gets marked as remotely suspended in
|
|
|
|
# that case.
|
|
|
|
|
|
|
|
@account.update!(last_webfingered_at: nil)
|
|
|
|
@account = ResolveAccountService.new.call(@account)
|
|
|
|
|
|
|
|
# Worth noting that it is possible that the remote has not only
|
|
|
|
# been suspended, but deleted permanently, in which case
|
|
|
|
# @account would now be nil.
|
|
|
|
end
|
|
|
|
|
2021-04-17 22:55:46 +10:00
|
|
|
def distribute_update_actor!
|
|
|
|
return unless @account.local?
|
|
|
|
|
|
|
|
account_reach_finder = AccountReachFinder.new(@account)
|
|
|
|
|
2023-03-15 13:45:15 +11:00
|
|
|
ActivityPub::DeliveryWorker.push_bulk(account_reach_finder.inboxes, limit: 1_000) do |inbox_url|
|
2021-04-17 22:55:46 +10:00
|
|
|
[signed_activity_json, @account.id, inbox_url]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-09-15 22:37:58 +10:00
|
|
|
def merge_into_home_timelines!
|
2023-09-05 23:37:23 +10:00
|
|
|
@account.followers_for_local_distribution.reorder(nil).find_each do |follower|
|
2020-11-07 23:16:00 +11:00
|
|
|
FeedManager.instance.merge_into_home(@account, follower)
|
2020-09-15 22:37:58 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_into_list_timelines!
|
2023-09-05 23:37:23 +10:00
|
|
|
@account.lists_for_local_distribution.reorder(nil).find_each do |list|
|
2020-09-15 22:37:58 +10:00
|
|
|
FeedManager.instance.merge_into_list(@account, list)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish_media_attachments!
|
|
|
|
attachment_names = MediaAttachment.attachment_definitions.keys
|
|
|
|
|
2023-12-01 00:30:35 +11:00
|
|
|
@account.media_attachments.find_each do |media_attachment|
|
2020-09-15 22:37:58 +10:00
|
|
|
attachment_names.each do |attachment_name|
|
|
|
|
attachment = media_attachment.public_send(attachment_name)
|
2023-05-04 13:33:55 +10:00
|
|
|
styles = MediaAttachment::DEFAULT_STYLES | attachment.styles.keys
|
2020-09-15 22:37:58 +10:00
|
|
|
|
2020-12-23 17:47:03 +11:00
|
|
|
next if attachment.blank?
|
|
|
|
|
2020-09-15 22:37:58 +10:00
|
|
|
styles.each do |style|
|
|
|
|
case Paperclip::Attachment.default_options[:storage]
|
|
|
|
when :s3
|
2022-12-20 03:55:17 +11:00
|
|
|
# Prevent useless S3 calls if ACLs are disabled
|
|
|
|
next if ENV['S3_PERMISSION'] == ''
|
|
|
|
|
2020-12-25 01:53:45 +11:00
|
|
|
begin
|
|
|
|
attachment.s3_object(style).acl.put(acl: Paperclip::Attachment.default_options[:s3_permissions])
|
|
|
|
rescue Aws::S3::Errors::NoSuchKey
|
|
|
|
Rails.logger.warn "Tried to change acl on non-existent key #{attachment.s3_object(style).key}"
|
2022-12-20 03:55:17 +11:00
|
|
|
rescue Aws::S3::Errors::NotImplemented => e
|
|
|
|
Rails.logger.error "Error trying to change ACL on #{attachment.s3_object(style).key}: #{e.message}"
|
2020-12-25 01:53:45 +11:00
|
|
|
end
|
2023-07-28 00:13:45 +10:00
|
|
|
when :fog, :azure
|
2020-09-15 22:37:58 +10:00
|
|
|
# Not supported
|
|
|
|
when :filesystem
|
2020-11-07 23:16:54 +11:00
|
|
|
begin
|
|
|
|
FileUtils.chmod(0o666 & ~File.umask, attachment.path(style)) unless attachment.path(style).nil?
|
|
|
|
rescue Errno::ENOENT
|
|
|
|
Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
|
|
|
|
end
|
2020-09-15 22:37:58 +10:00
|
|
|
end
|
2020-11-20 03:38:06 +11:00
|
|
|
|
|
|
|
CacheBusterWorker.perform_async(attachment.path(style)) if Rails.configuration.x.cache_buster_enabled
|
2020-09-15 22:37:58 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-04-17 22:55:46 +10:00
|
|
|
|
|
|
|
def signed_activity_json
|
|
|
|
@signed_activity_json ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account))
|
|
|
|
end
|
2020-09-15 22:37:58 +10:00
|
|
|
end
|