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.

124 lines
4.0 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 unsilence
  47. authorize @account, :unsilence?
  48. @account.unsilence!
  49. log_action :unsilence, @account
  50. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsilenced_msg', username: @account.acct)
  51. end
  52. def unsuspend
  53. authorize @account, :unsuspend?
  54. @account.unsuspend!
  55. Admin::UnsuspensionWorker.perform_async(@account.id)
  56. log_action :unsuspend, @account
  57. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.unsuspended_msg', username: @account.acct)
  58. end
  59. def redownload
  60. authorize @account, :redownload?
  61. @account.update!(last_webfingered_at: nil)
  62. ResolveAccountService.new.call(@account)
  63. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.redownloaded_msg', username: @account.acct)
  64. end
  65. def remove_avatar
  66. authorize @account, :remove_avatar?
  67. @account.avatar = nil
  68. @account.save!
  69. log_action :remove_avatar, @account.user
  70. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_avatar_msg', username: @account.acct)
  71. end
  72. def remove_header
  73. authorize @account, :remove_header?
  74. @account.header = nil
  75. @account.save!
  76. log_action :remove_header, @account.user
  77. redirect_to admin_account_path(@account.id), notice: I18n.t('admin.accounts.removed_header_msg', username: @account.acct)
  78. end
  79. private
  80. def set_account
  81. @account = Account.find(params[:id])
  82. end
  83. def require_remote_account!
  84. redirect_to admin_account_path(@account.id) if @account.local?
  85. end
  86. def require_local_account!
  87. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  88. end
  89. def filtered_accounts
  90. AccountFilter.new(filter_params).results
  91. end
  92. def filter_params
  93. params.slice(*AccountFilter::KEYS).permit(*AccountFilter::KEYS)
  94. end
  95. end
  96. end