X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/73d73c7b799ddb60363ddf409d8d301b27c82c00..0df7a1c38affbc50a9c7d8834f9822e398860d91:/services/api/app/controllers/application_controller.rb diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index 4b5a27d996..30027c8c78 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -1,3 +1,16 @@ +module ApiTemplateOverride + def allowed_to_render?(fieldset, field, model, options) + if options[:select] + return options[:select].include? field.to_s + end + super + end +end + +class ActsAsApi::ApiTemplate + prepend ApiTemplateOverride +end + require 'load_param' require 'record_filters' @@ -9,6 +22,7 @@ class ApplicationController < ActionController::Base ERROR_ACTIONS = [:render_error, :render_not_found] + respond_to :json protect_from_forgery @@ -33,7 +47,7 @@ class ApplicationController < ActionController::Base attr_accessor :resource_attrs def index - @objects.uniq!(&:id) + @objects.uniq!(&:id) if @select.nil? or @select.include? "id" if params[:eager] and params[:eager] != '0' and params[:eager] != 0 and params[:eager] != '' @objects.each(&:eager_load_associations) end @@ -246,6 +260,8 @@ class ApplicationController < ActionController::Base end end + @objects = @objects.select(@select.map { |s| "#{table_name}.#{ActiveRecord::Base.connection.quote_column_name s.to_s}" }.join ", ") if @select + @objects = @objects.uniq(ActiveRecord::Base.connection.quote_column_name @distinct.to_s) if @distinct @objects = @objects.order(@orders.join ", ") if @orders.any? @objects = @objects.limit(@limit) @objects = @objects.offset(@offset) @@ -403,7 +419,7 @@ class ApplicationController < ActionController::Base :self_link => "", :offset => @offset, :limit => @limit, - :items => @objects.as_api_response(nil) + :items => @objects.as_api_response(nil, {select: @select}) } if @objects.respond_to? :except @object_list[:items_available] = @objects.