pending_accounts_controller.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. module Admin
  3. class PendingAccountsController < BaseController
  4. before_action :set_accounts, only: :index
  5. def index
  6. @form = Form::AccountBatch.new
  7. end
  8. def batch
  9. @form = Form::AccountBatch.new(form_account_batch_params.merge(current_account: current_account, action: action_from_button))
  10. @form.save
  11. rescue ActionController::ParameterMissing
  12. flash[:alert] = I18n.t('admin.accounts.no_account_selected')
  13. ensure
  14. redirect_to admin_pending_accounts_path(current_params)
  15. end
  16. def approve_all
  17. Form::AccountBatch.new(current_account: current_account, account_ids: User.pending.pluck(:account_id), action: 'approve').save
  18. redirect_to admin_pending_accounts_path(current_params)
  19. end
  20. def reject_all
  21. Form::AccountBatch.new(current_account: current_account, account_ids: User.pending.pluck(:account_id), action: 'reject').save
  22. redirect_to admin_pending_accounts_path(current_params)
  23. end
  24. private
  25. def set_accounts
  26. @accounts = Account.joins(:user).merge(User.pending.recent).includes(user: :invite_request).page(params[:page])
  27. end
  28. def form_account_batch_params
  29. params.require(:form_account_batch).permit(:action, account_ids: [])
  30. end
  31. def action_from_button
  32. if params[:approve]
  33. 'approve'
  34. elsif params[:reject]
  35. 'reject'
  36. end
  37. end
  38. def current_params
  39. params.slice(:page).permit(:page)
  40. end
  41. end
  42. end