闭社主体 forked from https://github.com/tootsuite/mastodon
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.

140 lines
3.6 KiB

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