2019-04-06 17:53:45 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class PendingAccountsController < BaseController
|
|
|
|
before_action :set_accounts, only: :index
|
|
|
|
|
|
|
|
def index
|
|
|
|
@form = Form::AccountBatch.new
|
|
|
|
end
|
|
|
|
|
2019-04-08 18:35:41 +02:00
|
|
|
def batch
|
2019-04-06 17:53:45 +02:00
|
|
|
@form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
|
|
|
|
@form.save
|
|
|
|
rescue ActionController::ParameterMissing
|
2019-04-08 18:35:41 +02:00
|
|
|
flash[:alert] = I18n.t('admin.accounts.no_account_selected')
|
2019-04-06 17:53:45 +02:00
|
|
|
ensure
|
|
|
|
redirect_to admin_pending_accounts_path(current_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def approve_all
|
2019-04-09 07:19:52 +02:00
|
|
|
Form::AccountBatch.new(current_account: current_account, account_ids: User.pending.pluck(:account_id), action: 'approve').save
|
2019-04-06 17:53:45 +02:00
|
|
|
redirect_to admin_pending_accounts_path(current_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reject_all
|
2019-04-09 07:19:52 +02:00
|
|
|
Form::AccountBatch.new(current_account: current_account, account_ids: User.pending.pluck(:account_id), action: 'reject').save
|
2019-04-06 17:53:45 +02:00
|
|
|
redirect_to admin_pending_accounts_path(current_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_accounts
|
2019-04-10 00:36:01 +02:00
|
|
|
@accounts = Account.joins(:user).merge(User.pending.recent).includes(user: :invite_request).page(params[:page])
|
2019-04-06 17:53:45 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def form_account_batch_params
|
|
|
|
params.require(:form_account_batch).permit(:action, account_ids: [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def action_from_button
|
|
|
|
if params[:approve]
|
|
|
|
'approve'
|
|
|
|
elsif params[:reject]
|
|
|
|
'reject'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_params
|
|
|
|
params.slice(:page).permit(:page)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|