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.

127 lines
3.2 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]
  5. before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
  6. before_action :require_local_account!, only: [:enable, :memorialize]
  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 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. :silenced,
  91. :suspended,
  92. :username,
  93. :display_name,
  94. :email,
  95. :ip,
  96. :staff
  97. )
  98. end
  99. end
  100. end