accounts_controller.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # frozen_string_literal: true
  2. module Admin
  3. class AccountsController < BaseController
  4. before_action :set_account, except: [:index, :batch]
  5. before_action :require_remote_account!, only: [:redownload]
  6. before_action :require_local_account!, only: [:enable, :memorialize, :approve, :reject]
  7. def index
  8. authorize :account, :index?
  9. @accounts = filtered_accounts.page(params[:page])
  10. @form = Form::AccountBatch.new
  11. end
  12. def batch
  13. @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
  14. @form.save
  15. rescue ActionController::ParameterMissing
  16. flash[:alert] = I18n.t('admin.accounts.no_account_selected')
  17. ensure
  18. redirect_to admin_accounts_path(filter_params)
  19. end
  20. def show
  21. authorize @account, :show?
  22. @deletion_request = @account.deletion_request
  23. @account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
  24. @moderation_notes = @account.targeted_moderation_notes.latest
  25. @warnings = @account.strikes.includes(:target_account, :account, :appeal).latest
  26. @domain_block = DomainBlock.rule_for(@account.domain)
  27. end
  28. def memorialize
  29. authorize @account, :memorialize?
  30. @account.memorialize!
  31. log_action :memorialize, @account
  32. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.memorialized_msg', username: @account.acct)
  33. end
  34. def enable
  35. authorize @account.user, :enable?
  36. @account.user.enable!
  37. log_action :enable, @account.user
  38. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.enabled_msg', username: @account.acct)
  39. end
  40. def approve
  41. authorize @account.user, :approve?
  42. @account.user.approve!
  43. log_action :approve, @account.user
  44. redirect_to admin_accounts_path(status: 'pending'), notice: I18n.t('admin.accounts.approved_msg', username: @account.acct)
  45. end
  46. def reject
  47. authorize @account.user, :reject?
  48. DeleteAccountService.new.call(@account, reserve_email: false, reserve_username: false)
  49. log_action :reject, @account.user
  50. redirect_to admin_accounts_path(status: 'pending'), notice: I18n.t('admin.accounts.rejected_msg', username: @account.acct)
  51. end
  52. def destroy
  53. authorize @account, :destroy?
  54. Admin::AccountDeletionWorker.perform_async(@account.id)
  55. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.destroyed_msg', username: @account.acct)
  56. end
  57. def unsensitive
  58. authorize @account, :unsensitive?
  59. @account.unsensitize!
  60. log_action :unsensitive, @account
  61. redirect_to admin_account_path(@account.id)
  62. end
  63. def unsilence
  64. authorize @account, :unsilence?
  65. @account.unsilence!
  66. log_action :unsilence, @account
  67. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsilenced_msg', username: @account.acct)
  68. end
  69. def unsuspend
  70. authorize @account, :unsuspend?
  71. @account.unsuspend!
  72. Admin::UnsuspensionWorker.perform_async(@account.id)
  73. log_action :unsuspend, @account
  74. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsuspended_msg', username: @account.acct)
  75. end
  76. def redownload
  77. authorize @account, :redownload?
  78. @account.update!(last_webfingered_at: nil)
  79. ResolveAccountService.new.call(@account)
  80. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.redownloaded_msg', username: @account.acct)
  81. end
  82. def remove_avatar
  83. authorize @account, :remove_avatar?
  84. @account.avatar = nil
  85. @account.save!
  86. log_action :remove_avatar, @account.user
  87. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_avatar_msg', username: @account.acct)
  88. end
  89. def remove_header
  90. authorize @account, :remove_header?
  91. @account.header = nil
  92. @account.save!
  93. log_action :remove_header, @account.user
  94. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_header_msg', username: @account.acct)
  95. end
  96. def unblock_email
  97. authorize @account, :unblock_email?
  98. CanonicalEmailBlock.where(reference_account: @account).delete_all
  99. log_action :unblock_email, @account
  100. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unblocked_email_msg', username: @account.acct)
  101. end
  102. private
  103. def set_account
  104. @account = Account.find(params[:id])
  105. end
  106. def require_remote_account!
  107. redirect_to admin_account_path(@account.id) if @account.local?
  108. end
  109. def require_local_account!
  110. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  111. end
  112. def filtered_accounts
  113. AccountFilter.new(filter_params.with_defaults(order: 'recent')).results
  114. end
  115. def filter_params
  116. params.slice(:page, *AccountFilter::KEYS).permit(:page, *AccountFilter::KEYS)
  117. end
  118. def form_account_batch_params
  119. params.require(:form_account_batch).permit(:action, account_ids: [])
  120. end
  121. def action_from_button
  122. if params[:suspend]
  123. 'suspend'
  124. elsif params[:approve]
  125. 'approve'
  126. elsif params[:reject]
  127. 'reject'
  128. end
  129. end
  130. end
  131. end