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.

119 lines
2.9 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, :disable, :memorialize]
  5. before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
  6. before_action :require_local_account!, only: [:enable, :disable, :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. end
  16. def subscribe
  17. authorize @account, :subscribe?
  18. Pubsubhubbub::SubscribeWorker.perform_async(@account.id)
  19. redirect_to admin_account_path(@account.id)
  20. end
  21. def unsubscribe
  22. authorize @account, :unsubscribe?
  23. Pubsubhubbub::UnsubscribeWorker.perform_async(@account.id)
  24. redirect_to admin_account_path(@account.id)
  25. end
  26. def memorialize
  27. authorize @account, :memorialize?
  28. @account.memorialize!
  29. log_action :memorialize, @account
  30. redirect_to admin_account_path(@account.id)
  31. end
  32. def enable
  33. authorize @account.user, :enable?
  34. @account.user.enable!
  35. log_action :enable, @account.user
  36. redirect_to admin_account_path(@account.id)
  37. end
  38. def disable
  39. authorize @account.user, :disable?
  40. @account.user.disable!
  41. log_action :disable, @account.user
  42. redirect_to admin_account_path(@account.id)
  43. end
  44. def redownload
  45. authorize @account, :redownload?
  46. @account.reset_avatar!
  47. @account.reset_header!
  48. @account.save!
  49. redirect_to admin_account_path(@account.id)
  50. end
  51. def remove_avatar
  52. authorize @account, :remove_avatar?
  53. @account.avatar = nil
  54. @account.save!
  55. log_action :remove_avatar, @account.user
  56. redirect_to admin_account_path(@account.id)
  57. end
  58. def remove_header
  59. authorize @account, :remove_header?
  60. @account.header = nil
  61. @account.save!
  62. log_action :remove_header, @account.user
  63. redirect_to admin_account_path(@account.id)
  64. end
  65. private
  66. def set_account
  67. @account = Account.find(params[:id])
  68. end
  69. def require_remote_account!
  70. redirect_to admin_account_path(@account.id) if @account.local?
  71. end
  72. def require_local_account!
  73. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  74. end
  75. def filtered_accounts
  76. AccountFilter.new(filter_params).results
  77. end
  78. def filter_params
  79. params.permit(
  80. :local,
  81. :remote,
  82. :by_domain,
  83. :active,
  84. :silenced,
  85. :suspended,
  86. :username,
  87. :display_name,
  88. :email,
  89. :ip,
  90. :staff
  91. )
  92. end
  93. end
  94. end