0
0
Fork 0

Admin accounts controller cleanup (#1664)

* Remove unused account_params method in admin/accounts controller

* Introduce AccountFilter to find accounts

* Use AccountFilter in admin/accounts controller

* Use more restful routes admin silence and suspension area

* Add admin/silences and admin/suspensions controllers
This commit is contained in:
Matt Jankowski 2017-04-13 07:04:23 -04:00 committed by Eugen
parent 0e39cc6a35
commit 3a9eb81a80
9 changed files with 182 additions and 44 deletions

View file

@ -2,49 +2,29 @@
module Admin
class AccountsController < BaseController
before_action :set_account, except: :index
def index
@accounts = Account.alphabetic.page(params[:page])
@accounts = @accounts.local if params[:local].present?
@accounts = @accounts.remote if params[:remote].present?
@accounts = @accounts.where(domain: params[:by_domain]) if params[:by_domain].present?
@accounts = @accounts.silenced if params[:silenced].present?
@accounts = @accounts.recent if params[:recent].present?
@accounts = @accounts.suspended if params[:suspended].present?
@accounts = filtered_accounts.page(params[:page])
end
def show; end
def suspend
Admin::SuspensionWorker.perform_async(@account.id)
redirect_to admin_accounts_path
end
def unsuspend
@account.update(suspended: false)
redirect_to admin_accounts_path
end
def silence
@account.update(silenced: true)
redirect_to admin_accounts_path
end
def unsilence
@account.update(silenced: false)
redirect_to admin_accounts_path
def show
@account = Account.find(params[:id])
end
private
def set_account
@account = Account.find(params[:id])
def filtered_accounts
AccountFilter.new(filter_params).results
end
def account_params
params.require(:account).permit(:silenced, :suspended)
def filter_params
params.permit(
:local,
:remote,
:by_domain,
:silenced,
:recent,
:suspended
)
end
end
end