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