闭社主体 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.

108 lines
2.7 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, :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. private
  59. def set_account
  60. @account = Account.find(params[:id])
  61. end
  62. def require_remote_account!
  63. redirect_to admin_account_path(@account.id) if @account.local?
  64. end
  65. def require_local_account!
  66. redirect_to admin_account_path(@account.id) unless @account.local? && @account.user.present?
  67. end
  68. def filtered_accounts
  69. AccountFilter.new(filter_params).results
  70. end
  71. def filter_params
  72. params.permit(
  73. :local,
  74. :remote,
  75. :by_domain,
  76. :silenced,
  77. :recent,
  78. :suspended,
  79. :username,
  80. :display_name,
  81. :email,
  82. :ip,
  83. :staff
  84. )
  85. end
  86. end
  87. end