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.

131 lines
4.2 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class AccountsController < BaseController
  4. before_action :set_account, except: [:index]
  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. end
  11. def show
  12. authorize @account, :show?
  13. @deletion_request = @account.deletion_request
  14. @account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
  15. @moderation_notes = @account.targeted_moderation_notes.latest
  16. @warnings = @account.targeted_account_warnings.latest.custom
  17. @domain_block = DomainBlock.rule_for(@account.domain)
  18. end
  19. def memorialize
  20. authorize @account, :memorialize?
  21. @account.memorialize!
  22. log_action :memorialize, @account
  23. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.memorialized_msg', username: @account.acct)
  24. end
  25. def enable
  26. authorize @account.user, :enable?
  27. @account.user.enable!
  28. log_action :enable, @account.user
  29. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.enabled_msg', username: @account.acct)
  30. end
  31. def approve
  32. authorize @account.user, :approve?
  33. @account.user.approve!
  34. redirect_to admin_pending_accounts_path, notice: I18n.t('admin.accounts.approved_msg', username: @account.acct)
  35. end
  36. def reject
  37. authorize @account.user, :reject?
  38. DeleteAccountService.new.call(@account, reserve_email: false, reserve_username: false)
  39. redirect_to admin_pending_accounts_path, notice: I18n.t('admin.accounts.rejected_msg', username: @account.acct)
  40. end
  41. def destroy
  42. authorize @account, :destroy?
  43. Admin::AccountDeletionWorker.perform_async(@account.id)
  44. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.destroyed_msg', username: @account.acct)
  45. end
  46. def unsensitive
  47. authorize @account, :unsensitive?
  48. @account.unsensitize!
  49. log_action :unsensitive, @account
  50. redirect_to admin_account_path(@account.id)
  51. end
  52. def unsilence
  53. authorize @account, :unsilence?
  54. @account.unsilence!
  55. log_action :unsilence, @account
  56. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsilenced_msg', username: @account.acct)
  57. end
  58. def unsuspend
  59. authorize @account, :unsuspend?
  60. @account.unsuspend!
  61. Admin::UnsuspensionWorker.perform_async(@account.id)
  62. log_action :unsuspend, @account
  63. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsuspended_msg', username: @account.acct)
  64. end
  65. def redownload
  66. authorize @account, :redownload?
  67. @account.update!(last_webfingered_at: nil)
  68. ResolveAccountService.new.call(@account)
  69. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.redownloaded_msg', username: @account.acct)
  70. end
  71. def remove_avatar
  72. authorize @account, :remove_avatar?
  73. @account.avatar = nil
  74. @account.save!
  75. log_action :remove_avatar, @account.user
  76. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_avatar_msg', username: @account.acct)
  77. end
  78. def remove_header
  79. authorize @account, :remove_header?
  80. @account.header = nil
  81. @account.save!
  82. log_action :remove_header, @account.user
  83. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_header_msg', username: @account.acct)
  84. end
  85. private
  86. def set_account
  87. @account = Account.find(params[:id])
  88. end
  89. def require_remote_account!
  90. redirect_to admin_account_path(@account.id) if @account.local?
  91. end
  92. def require_local_account!
  93. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  94. end
  95. def filtered_accounts
  96. AccountFilter.new(filter_params).results
  97. end
  98. def filter_params
  99. params.slice(*AccountFilter::KEYS).permit(*AccountFilter::KEYS)
  100. end
  101. end
  102. end