2016-12-06 16:41:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class SuspendAccountService < BaseService
|
2020-09-15 13:37:58 +01:00
|
|
|
def call(account)
|
2016-12-06 16:41:42 +00:00
|
|
|
@account = account
|
|
|
|
|
2020-09-15 13:37:58 +01:00
|
|
|
suspend!
|
|
|
|
unmerge_from_home_timelines!
|
|
|
|
unmerge_from_list_timelines!
|
|
|
|
privatize_media_attachments!
|
2016-12-06 16:41:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2020-09-15 13:37:58 +01:00
|
|
|
def suspend!
|
|
|
|
@account.suspend! unless @account.suspended?
|
2019-03-10 15:18:58 +00:00
|
|
|
end
|
|
|
|
|
2020-09-15 13:37:58 +01:00
|
|
|
def unmerge_from_home_timelines!
|
|
|
|
@account.followers_for_local_distribution.find_each do |follower|
|
2020-11-07 12:16:00 +00:00
|
|
|
FeedManager.instance.unmerge_from_home(@account, follower)
|
2017-11-07 18:06:44 +00:00
|
|
|
end
|
2017-06-14 17:01:27 +01:00
|
|
|
end
|
|
|
|
|
2020-09-15 13:37:58 +01: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 15:32:44 +01:00
|
|
|
end
|
2016-12-06 16:41:42 +00:00
|
|
|
end
|
|
|
|
|
2020-09-15 13:37:58 +01:00
|
|
|
def privatize_media_attachments!
|
|
|
|
attachment_names = MediaAttachment.attachment_definitions.keys
|
2018-12-03 00:32:08 +00:00
|
|
|
|
2020-09-15 13:37:58 +01: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 15:32:44 +01:00
|
|
|
|
2020-09-15 13:37:58 +01:00
|
|
|
styles.each do |style|
|
|
|
|
case Paperclip::Attachment.default_options[:storage]
|
|
|
|
when :s3
|
2020-11-07 12:16:54 +00:00
|
|
|
attachment.s3_object(style).acl.put(acl: 'private')
|
2020-09-15 13:37:58 +01:00
|
|
|
when :fog
|
|
|
|
# Not supported
|
|
|
|
when :filesystem
|
2020-11-07 12:16:54 +00: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 13:37:58 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-03 00:32:08 +00:00
|
|
|
end
|
|
|
|
end
|
2016-12-06 16:41:42 +00:00
|
|
|
end
|