PageRenderTime 1083ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/backend/app/controllers/spree/admin/search_controller.rb

https://gitlab.com/shinvdu/spree
Ruby | 50 lines | 41 code | 6 blank | 3 comment | 3 complexity | 373cc4cdf575153d785443abbbc2d0de MD5 | raw file
  1. module Spree
  2. module Admin
  3. class SearchController < Spree::Admin::BaseController
  4. respond_to :json
  5. layout false
  6. # http://spreecommerce.com/blog/2010/11/02/json-hijacking-vulnerability/
  7. before_action :check_json_authenticity, only: :index
  8. # TODO: Clean this up by moving searching out to user_class_extensions
  9. # And then JSON building with something like Active Model Serializers
  10. def users
  11. if params[:ids]
  12. @users = Spree.user_class.where(id: params[:ids].split(',').flatten)
  13. else
  14. @users = Spree.user_class.ransack({
  15. m: 'or',
  16. email_start: params[:q],
  17. ship_address_firstname_start: params[:q],
  18. ship_address_lastname_start: params[:q],
  19. bill_address_firstname_start: params[:q],
  20. bill_address_lastname_start: params[:q]
  21. }).result.limit(10)
  22. end
  23. end
  24. def products
  25. if params[:ids]
  26. @products = Product.where(id: params[:ids].split(",").flatten)
  27. else
  28. @products = Product.ransack(params[:q]).result
  29. end
  30. @products = @products.distinct.page(params[:page]).per(params[:per_page])
  31. expires_in 15.minutes, public: true
  32. headers['Surrogate-Control'] = "max-age=#{15.minutes}"
  33. end
  34. def tags
  35. @tags =
  36. if params[:ids]
  37. Tag.where(id: params[:ids].split(",").flatten)
  38. else
  39. Tag.ransack(params[:q]).result
  40. end
  41. end
  42. end
  43. end
  44. end