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.

97 lines
2.5 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class AccountsController < BaseController
  4. before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :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. private
  52. def set_account
  53. @account = Account.find(params[:id])
  54. end
  55. def require_remote_account!
  56. redirect_to admin_account_path(@account.id) if @account.local?
  57. end
  58. def require_local_account!
  59. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  60. end
  61. def filtered_accounts
  62. AccountFilter.new(filter_params).results
  63. end
  64. def filter_params
  65. params.permit(
  66. :local,
  67. :remote,
  68. :by_domain,
  69. :silenced,
  70. :recent,
  71. :suspended,
  72. :username,
  73. :display_name,
  74. :email,
  75. :ip,
  76. :staff
  77. )
  78. end
  79. end
  80. end