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.

76 lines
2.2 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. styles.each do |style|
  45. case Paperclip::Attachment.default_options[:storage]
  46. when :s3
  47. attachment.s3_object(style).acl.put(acl: Paperclip::Attachment.default_options[:s3_permissions])
  48. when :fog
  49. # Not supported
  50. when :filesystem
  51. begin
  52. FileUtils.chmod(0o666 & ~File.umask, attachment.path(style)) unless attachment.path(style).nil?
  53. rescue Errno::ENOENT
  54. Rails.logger.warn "Tried to change permission on non-existent file #{attachment.path(style)}"
  55. end
  56. end
  57. end
  58. end
  59. end
  60. end
  61. end