accounts_controller.rb 5.5 KB

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