You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5 KiB

  1. # frozen_string_literal: true
  2. class UnsuspendAccountService < BaseService
  3. def call(account)
  4. @account = account
  5. unsuspend!
  6. refresh_remote_account!
  7. return if @account.nil?
  8. merge_into_home_timelines!
  9. merge_into_list_timelines!
  10. publish_media_attachments!
  11. end
  12. private
  13. def unsuspend!
  14. @account.unsuspend! if @account.suspended?
  15. end
  16. def refresh_remote_account!
  17. return if @account.local?
  18. # While we had the remote account suspended, it could be that
  19. # it got suspended on its origin, too. So, we need to refresh
  20. # it straight away so it gets marked as remotely suspended in
  21. # that case.
  22. @account.update!(last_webfingered_at: nil)
  23. @account = ResolveAccountService.new.call(@account)
  24. # Worth noting that it is possible that the remote has not only
  25. # been suspended, but deleted permanently, in which case
  26. # @account would now be nil.
  27. end
  28. def merge_into_home_timelines!
  29. @account.followers_for_local_distribution.find_each do |follower|
  30. FeedManager.instance.merge_into_home(@account, follower)
  31. end
  32. end
  33. def merge_into_list_timelines!
  34. @account.lists_for_local_distribution.find_each do |list|
  35. FeedManager.instance.merge_into_list(@account, list)
  36. end
  37. end
  38. def publish_media_attachments!
  39. attachment_names = MediaAttachment.attachment_definitions.keys
  40. @account.media_attachments.find_each do |media_attachment|
  41. attachment_names.each do |attachment_name|
  42. attachment = media_attachment.public_send(attachment_name)
  43. styles = [:original] | attachment.styles.keys
  44. next if attachment.blank?
  45. styles.each do |style|
  46. case Paperclip::Attachment.default_options[:storage]
  47. when :s3
  48. begin
  49. attachment.s3_object(style).acl.put(acl: Paperclip::Attachment.default_options[:s3_permissions])
  50. rescue Aws::S3::Errors::NoSuchKey
  51. Rails.logger.warn "Tried to change acl on non-existent key #{attachment.s3_object(style).key}"
  52. end
  53. when :fog
  54. # Not supported
  55. when :filesystem
  56. begin
  57. FileUtils.chmod(0o666 & ~File.umask, attachment.path(style)) unless attachment.path(style).nil?
  58. rescue Errno::ENOENT
  59. Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
  60. end
  61. end
  62. CacheBusterWorker.perform_async(attachment.path(style)) if Rails.configuration.x.cache_buster_enabled
  63. end
  64. end
  65. end
  66. end
  67. end