100% free for Open Source, forever. Get another set of eyes on your code.

100% free for Open Source, forever. Get another set of eyes on your code.

aa8796c2
B

Spree::Admin::SearchController

Updated 12 days ago.
  • Complex method #users (complexity = 35)

          def users
            if params[:ids]
              @users = Spree.user_class.where(id: params[:ids].split(',').flatten)
            else
              @users = Spree.user_class.ransack({
    
    View more
  • Complex method #products (complexity = 30)

          def products
            if params[:ids]
              @products = Product.where(id: params[:ids].split(",").flatten)
            else
              @products = Product.ransack(params[:q]).result
    
    View more
module Spree
  module Admin
    class SearchController < Spree::Admin::BaseController
      # http://spreecommerce.com/blog/2010/11/02/json-hijacking-vulnerability/
      before_action :check_json_authenticity, only: :index
      respond_to :json

      # TODO: Clean this up by moving searching out to user_class_extensions
      # And then JSON building with something like Active Model Serializers
      def users
        if params[:ids]
          @users = Spree.user_class.where(id: params[:ids].split(',').flatten)
        else
          @users = Spree.user_class.ransack({
            m: 'or',
            email_start: params[:q],
            ship_address_firstname_start: params[:q],
            ship_address_lastname_start: params[:q],
            bill_address_firstname_start: params[:q],
            bill_address_lastname_start: params[:q]
          }).result.limit(10)
        end
      end

      def products
        if params[:ids]
          @products = Product.where(id: params[:ids].split(",").flatten)
        else
          @products = Product.ransack(params[:q]).result
        end

        @products = @products.distinct.page(params[:page]).per(params[:per_page])
        expires_in 15.minutes, public: true
        headers['Surrogate-Control'] = "max-age=#{15.minutes}"
      end
    end
  end
end
67
Complexity
0
Duplication
38
Lines
2
Methods
33.3
Complexity / M
2
Churn
32
Lines of Code
16
LOC / Method