19015: installer fix: work around a Passenger issue with the detection of RVM
[arvados.git] / services / api / lib / load_param.rb
index a08b8b78a532d90fce3bb79deba6b6aabe3d5031..9a360c538b6e432e36ad72cfe00d98493af925b6 100644 (file)
@@ -56,7 +56,7 @@ module LoadParam
         raise ArgumentError.new("Invalid value for limit parameter")
       end
       @limit = [params[:limit].to_i,
-                Rails.configuration.max_items_per_response].min
+                Rails.configuration.API.MaxItemsPerResponse].min
     else
       @limit = DEFAULT_LIMIT
     end
@@ -145,19 +145,23 @@ module LoadParam
       end
     end
 
+    @distinct = params[:distinct] && true
+  end
+
+  def load_select_param
     case params[:select]
     when Array
       @select = params[:select]
     when String
       begin
         @select = SafeJSON.load(params[:select])
-        raise unless @select.is_a? Array or @select.nil?
+        raise unless @select.is_a? Array or @select.nil? or !@select
       rescue
         raise ArgumentError.new("Could not parse \"select\" param as an array")
       end
     end
 
-    if @select
+    if @select && @orders
       # Any ordering columns must be selected when doing select,
       # otherwise it is an SQL error, so filter out invaliding orderings.
       @orders.select! { |o|
@@ -166,9 +170,6 @@ module LoadParam
         @select.select { |s| col == "#{table_name}.#{s}" }.any?
       }
     end
-
-    @distinct = true if (params[:distinct] == true || params[:distinct] == "true")
-    @distinct = false if (params[:distinct] == false || params[:distinct] == "false")
   end
 
 end