accounts_controller.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. class Api::V2::Admin::AccountsController < Api::V1::Admin::AccountsController
  3. FILTER_PARAMS = %i(
  4. origin
  5. status
  6. permissions
  7. username
  8. by_domain
  9. display_name
  10. email
  11. ip
  12. invited_by
  13. role_ids
  14. ).freeze
  15. PAGINATION_PARAMS = (%i(limit) + FILTER_PARAMS).freeze
  16. private
  17. def next_path
  18. api_v2_admin_accounts_url(pagination_params(max_id: pagination_max_id)) if records_continue?
  19. end
  20. def prev_path
  21. api_v2_admin_accounts_url(pagination_params(min_id: pagination_since_id)) unless @accounts.empty?
  22. end
  23. def filtered_accounts
  24. AccountFilter.new(translated_filter_params).results
  25. end
  26. def translated_filter_params
  27. translated_params = filter_params.slice(*AccountFilter::KEYS)
  28. translated_params[:role_ids] = UserRole.that_can(:manage_reports).map(&:id) if params[:permissions] == 'staff'
  29. translated_params
  30. end
  31. def filter_params
  32. params.permit(*FILTER_PARAMS, role_ids: [])
  33. end
  34. def pagination_params(core_params)
  35. params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
  36. end
  37. end