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.

93 lines
2.3 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. redirect_to admin_account_path(@account.id)
  30. end
  31. def enable
  32. authorize @account.user, :enable?
  33. @account.user.enable!
  34. redirect_to admin_account_path(@account.id)
  35. end
  36. def disable
  37. authorize @account.user, :disable?
  38. @account.user.disable!
  39. redirect_to admin_account_path(@account.id)
  40. end
  41. def redownload
  42. authorize @account, :redownload?
  43. @account.reset_avatar!
  44. @account.reset_header!
  45. @account.save!
  46. redirect_to admin_account_path(@account.id)
  47. end
  48. private
  49. def set_account
  50. @account = Account.find(params[:id])
  51. end
  52. def require_remote_account!
  53. redirect_to admin_account_path(@account.id) if @account.local?
  54. end
  55. def require_local_account!
  56. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  57. end
  58. def filtered_accounts
  59. AccountFilter.new(filter_params).results
  60. end
  61. def filter_params
  62. params.permit(
  63. :local,
  64. :remote,
  65. :by_domain,
  66. :silenced,
  67. :recent,
  68. :suspended,
  69. :username,
  70. :display_name,
  71. :email,
  72. :ip
  73. )
  74. end
  75. end
  76. end