2016-12-06 08:41:42 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SuspendAccountService < BaseService
|
2020-11-07 15:28:39 -08:00
|
|
|
include Payloadable
|
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
def call(account)
|
2016-12-06 08:41:42 -08:00
|
|
|
@account = account
|
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
suspend!
|
2020-11-07 15:28:39 -08:00
|
|
|
reject_remote_follows!
|
|
|
|
distribute_update_actor!
|
2020-09-15 05:37:58 -07:00
|
|
|
unmerge_from_home_timelines!
|
|
|
|
unmerge_from_list_timelines!
|
|
|
|
privatize_media_attachments!
|
2016-12-06 08:41:42 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
def suspend!
|
|
|
|
@account.suspend! unless @account.suspended?
|
2019-03-10 08:18:58 -07:00
|
|
|
end
|
|
|
|
|
2020-11-07 15:28:39 -08:00
|
|
|
def reject_remote_follows!
|
|
|
|
return if @account.local? || !@account.activitypub?
|
|
|
|
|
|
|
|
# When suspending a remote account, the account obviously doesn't
|
|
|
|
# actually become suspended on its origin server, i.e. unlike a
|
|
|
|
# locally suspended account it continues to have access to its home
|
|
|
|
# feed and other content. To prevent it from being able to continue
|
|
|
|
# to access toots it would receive because it follows local accounts,
|
|
|
|
# we have to force it to unfollow them. Unfortunately, there is no
|
|
|
|
# counterpart to this operation, i.e. you can't then force a remote
|
|
|
|
# account to re-follow you, so this part is not reversible.
|
|
|
|
|
|
|
|
follows = Follow.where(account: @account).to_a
|
|
|
|
|
|
|
|
ActivityPub::DeliveryWorker.push_bulk(follows) do |follow|
|
|
|
|
[Oj.dump(serialize_payload(follow, ActivityPub::RejectFollowSerializer)), follow.target_account_id, @account.inbox_url]
|
|
|
|
end
|
|
|
|
|
2020-11-08 09:29:48 -08:00
|
|
|
follows.each(&:destroy)
|
2020-11-07 15:28:39 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
def distribute_update_actor!
|
|
|
|
ActivityPub::UpdateDistributionWorker.perform_async(@account.id) if @account.local?
|
|
|
|
end
|
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
def unmerge_from_home_timelines!
|
|
|
|
@account.followers_for_local_distribution.find_each do |follower|
|
2020-11-07 04:16:00 -08:00
|
|
|
FeedManager.instance.unmerge_from_home(@account, follower)
|
2017-11-07 10:06:44 -08:00
|
|
|
end
|
2017-06-14 09:01:27 -07:00
|
|
|
end
|
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
def unmerge_from_list_timelines!
|
|
|
|
@account.lists_for_local_distribution.find_each do |list|
|
|
|
|
FeedManager.instance.unmerge_from_list(@account, list)
|
2019-09-11 07:32:44 -07:00
|
|
|
end
|
2016-12-06 08:41:42 -08:00
|
|
|
end
|
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
def privatize_media_attachments!
|
|
|
|
attachment_names = MediaAttachment.attachment_definitions.keys
|
2018-12-02 16:32:08 -08:00
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
@account.media_attachments.find_each do |media_attachment|
|
|
|
|
attachment_names.each do |attachment_name|
|
|
|
|
attachment = media_attachment.public_send(attachment_name)
|
|
|
|
styles = [:original] | attachment.styles.keys
|
2019-09-11 07:32:44 -07:00
|
|
|
|
2020-09-15 05:37:58 -07:00
|
|
|
styles.each do |style|
|
|
|
|
case Paperclip::Attachment.default_options[:storage]
|
|
|
|
when :s3
|
2020-11-07 04:16:54 -08:00
|
|
|
attachment.s3_object(style).acl.put(acl: 'private')
|
2020-09-15 05:37:58 -07:00
|
|
|
when :fog
|
|
|
|
# Not supported
|
|
|
|
when :filesystem
|
2020-11-07 04:16:54 -08:00
|
|
|
begin
|
|
|
|
FileUtils.chmod(0o600 & ~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 05:37:58 -07:00
|
|
|
end
|
2020-11-19 08:38:06 -08:00
|
|
|
|
|
|
|
CacheBusterWorker.perform_async(attachment.path(style)) if Rails.configuration.x.cache_buster_enabled
|
2020-09-15 05:37:58 -07:00
|
|
|
end
|
|
|
|
end
|
2018-12-02 16:32:08 -08:00
|
|
|
end
|
|
|
|
end
|
2016-12-06 08:41:42 -08:00
|
|
|
end
|