accounts_controller.rb 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. redirect_to admin_accounts_path(status: 'pending'), notice: I18n.t('admin.accounts.approved_msg', username: @account.acct)
  49. end
  50. def reject
  51. authorize @account.user, :reject?
  52. DeleteAccountService.new.call(@account, reserve_email: false, reserve_username: false)
  53. redirect_to admin_accounts_path(status: 'pending'), notice: I18n.t('admin.accounts.rejected_msg', username: @account.acct)
  54. end
  55. def destroy
  56. authorize @account, :destroy?
  57. Admin::AccountDeletionWorker.perform_async(@account.id)
  58. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.destroyed_msg', username: @account.acct)
  59. end
  60. def unsensitive
  61. authorize @account, :unsensitive?
  62. @account.unsensitize!
  63. log_action :unsensitive, @account
  64. redirect_to admin_account_path(@account.id)
  65. end
  66. def unsilence
  67. authorize @account, :unsilence?
  68. @account.unsilence!
  69. log_action :unsilence, @account
  70. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsilenced_msg', username: @account.acct)
  71. end
  72. def unsuspend
  73. authorize @account, :unsuspend?
  74. @account.unsuspend!
  75. Admin::UnsuspensionWorker.perform_async(@account.id)
  76. log_action :unsuspend, @account
  77. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsuspended_msg', username: @account.acct)
  78. end
  79. def redownload
  80. authorize @account, :redownload?
  81. @account.update!(last_webfingered_at: nil)
  82. ResolveAccountService.new.call(@account)
  83. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.redownloaded_msg', username: @account.acct)
  84. end
  85. def remove_avatar
  86. authorize @account, :remove_avatar?
  87. @account.avatar = nil
  88. @account.save!
  89. log_action :remove_avatar, @account.user
  90. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_avatar_msg', username: @account.acct)
  91. end
  92. def remove_header
  93. authorize @account, :remove_header?
  94. @account.header = nil
  95. @account.save!
  96. log_action :remove_header, @account.user
  97. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_header_msg', username: @account.acct)
  98. end
  99. def unblock_email
  100. authorize @account, :unblock_email?
  101. CanonicalEmailBlock.where(reference_account: @account).delete_all
  102. log_action :unblock_email, @account
  103. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unblocked_email_msg', username: @account.acct)
  104. end
  105. private
  106. def set_account
  107. @account = Account.find(params[:id])
  108. end
  109. def require_remote_account!
  110. redirect_to admin_account_path(@account.id) if @account.local?
  111. end
  112. def require_local_account!
  113. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  114. end
  115. def filtered_accounts
  116. AccountFilter.new(filter_params.with_defaults(order: 'recent')).results
  117. end
  118. def filter_params
  119. params.slice(:page, *AccountFilter::KEYS).permit(:page, *AccountFilter::KEYS)
  120. end
  121. def form_account_batch_params
  122. params.require(:form_account_batch).permit(:action, account_ids: [])
  123. end
  124. def action_from_button
  125. if params[:suspend]
  126. 'suspend'
  127. elsif params[:approve]
  128. 'approve'
  129. elsif params[:reject]
  130. 'reject'
  131. end
  132. end
  133. end
  134. end