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.

129 lines
3.2 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class AccountsController < BaseController
  4. before_action :set_account, only: [:show, :redownload, :remove_avatar, :remove_header, :enable, :unsilence, :unsuspend, :memorialize, :approve, :reject]
  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. @account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
  14. @moderation_notes = @account.targeted_moderation_notes.latest
  15. @warnings = @account.targeted_account_warnings.latest.custom
  16. end
  17. def memorialize
  18. authorize @account, :memorialize?
  19. @account.memorialize!
  20. log_action :memorialize, @account
  21. redirect_to admin_account_path(@account.id)
  22. end
  23. def enable
  24. authorize @account.user, :enable?
  25. @account.user.enable!
  26. log_action :enable, @account.user
  27. redirect_to admin_account_path(@account.id)
  28. end
  29. def approve
  30. authorize @account.user, :approve?
  31. @account.user.approve!
  32. redirect_to admin_pending_accounts_path
  33. end
  34. def reject
  35. authorize @account.user, :reject?
  36. SuspendAccountService.new.call(@account, including_user: true, destroy: true, skip_distribution: true)
  37. redirect_to admin_pending_accounts_path
  38. end
  39. def unsilence
  40. authorize @account, :unsilence?
  41. @account.unsilence!
  42. log_action :unsilence, @account
  43. redirect_to admin_account_path(@account.id)
  44. end
  45. def unsuspend
  46. authorize @account, :unsuspend?
  47. @account.unsuspend!
  48. log_action :unsuspend, @account
  49. redirect_to admin_account_path(@account.id)
  50. end
  51. def redownload
  52. authorize @account, :redownload?
  53. @account.update!(last_webfingered_at: nil)
  54. ResolveAccountService.new.call(@account)
  55. redirect_to admin_account_path(@account.id)
  56. end
  57. def remove_avatar
  58. authorize @account, :remove_avatar?
  59. @account.avatar = nil
  60. @account.save!
  61. log_action :remove_avatar, @account.user
  62. redirect_to admin_account_path(@account.id)
  63. end
  64. def remove_header
  65. authorize @account, :remove_header?
  66. @account.header = nil
  67. @account.save!
  68. log_action :remove_header, @account.user
  69. redirect_to admin_account_path(@account.id)
  70. end
  71. private
  72. def set_account
  73. @account = Account.find(params[:id])
  74. end
  75. def require_remote_account!
  76. redirect_to admin_account_path(@account.id) if @account.local?
  77. end
  78. def require_local_account!
  79. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  80. end
  81. def filtered_accounts
  82. AccountFilter.new(filter_params).results
  83. end
  84. def filter_params
  85. params.permit(
  86. :local,
  87. :remote,
  88. :by_domain,
  89. :active,
  90. :pending,
  91. :disabled,
  92. :silenced,
  93. :suspended,
  94. :username,
  95. :display_name,
  96. :email,
  97. :ip,
  98. :staff
  99. )
  100. end
  101. end
  102. end