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.

82 lines
1.6 KiB

  1. # frozen_string_literal: true
  2. class ApproveAppealService < BaseService
  3. def call(appeal, current_account)
  4. @appeal = appeal
  5. @strike = appeal.strike
  6. @current_account = current_account
  7. ApplicationRecord.transaction do
  8. undo_strike_action!
  9. mark_strike_as_appealed!
  10. end
  11. queue_workers!
  12. notify_target_account!
  13. end
  14. private
  15. def target_account
  16. @strike.target_account
  17. end
  18. def undo_strike_action!
  19. case @strike.action
  20. when 'disable'
  21. undo_disable!
  22. when 'delete_statuses'
  23. undo_delete_statuses!
  24. when 'mark_statuses_as_sensitive'
  25. undo_mark_statuses_as_sensitive!
  26. when 'sensitive'
  27. undo_sensitive!
  28. when 'silence'
  29. undo_silence!
  30. when 'suspend'
  31. undo_suspend!
  32. end
  33. end
  34. def mark_strike_as_appealed!
  35. @appeal.approve!(@current_account)
  36. @strike.touch(:overruled_at)
  37. end
  38. def undo_disable!
  39. target_account.user.enable!
  40. end
  41. def undo_delete_statuses!
  42. # Cannot be undone
  43. end
  44. def undo_mark_statuses_as_sensitive!
  45. @strike.statuses.includes(:media_attachments).each do |status|
  46. UpdateStatusService.new.call(status, @current_account.id, sensitive: false) if status.with_media?
  47. end
  48. end
  49. def undo_sensitive!
  50. target_account.unsensitize!
  51. end
  52. def undo_silence!
  53. target_account.unsilence!
  54. end
  55. def undo_suspend!
  56. target_account.unsuspend!
  57. end
  58. def queue_workers!
  59. case @strike.action
  60. when 'suspend'
  61. Admin::UnsuspensionWorker.perform_async(target_account.id)
  62. end
  63. end
  64. def notify_target_account!
  65. UserMailer.appeal_approved(target_account.user, @appeal).deliver_later
  66. end
  67. end