def show
if @object
- render json: @object.as_api_response(:superuser)
+ render json: @object.as_api_response
else
render_not_found("object not found")
end
:with => :render_not_found
rescue_from ActionController::UnknownController,
:with => :render_not_found
- rescue_from ActionController::UnknownAction,
+ rescue_from AbstractController::ActionNotFound,
:with => :render_not_found
rescue_from ArvadosModel::PermissionDeniedError,
:with => :render_error
else
errors = [e.inspect]
end
- render json: { errors: errors }, status: 422
+ status = e.respond_to?(:http_status) ? e.http_status : 422
+ render json: { errors: errors }, status: status
end
def render_not_found(e=ActionController::RoutingError.new("Path not found"))
@where = params[:where]
elsif params[:where].is_a? String
begin
- @where = Oj.load(params[:where])
+ @where = Oj.load(params[:where], symbol_keys: true)
rescue
raise ArgumentError.new("Could not parse \"where\" param as an object")
end
if !@where.empty?
conditions = ['1=1']
@where.each do |attr,value|
- if attr == 'any' or attr == :any
+ if attr == :any
if value.is_a?(Array) and
value[0] == 'contains' and
model_class.columns.collect(&:name).index('name') then
return @attrs if @attrs
@attrs = params[resource_name]
if @attrs.is_a? String
- @attrs = Oj.load @attrs
+ @attrs = Oj.load @attrs, symbol_keys: true
end
unless @attrs.is_a? Hash
message = "No #{resource_name}"
end
def thread_with_auth_info
+ Thread.current[:request_starttime] = Time.now
Thread.current[:api_url_base] = root_url.sub(/\/$/,'') + '/arvados/v1'
begin
user = nil
if params[:id] and params[:id].match /\D/
params[:uuid] = params.delete :id
end
- @object = model_class.where('uuid=?', params[:uuid]).first
+ @where = { uuid: params[:uuid] }
+ find_objects_for_index
+ @object = @objects.first
end
def self.accept_attribute_as_json(attr, force_class=nil)
def accept_attribute_as_json(attr, force_class)
if params[resource_name].is_a? Hash
if params[resource_name][attr].is_a? String
- params[resource_name][attr] = Oj.load params[resource_name][attr]
+ params[resource_name][attr] = Oj.load(params[resource_name][attr],
+ symbol_keys: true)
if force_class and !params[resource_name][attr].is_a? force_class
raise TypeError.new("#{resource_name}[#{attr.to_s}] must be a #{force_class.to_s}")
end
def render_list
@object_list = {
- :kind => "arvados##{resource_name}List",
+ :kind => "arvados##{(@response_resource_name || resource_name).camelize(:lower)}List",
:etag => "",
:self_link => "",
:next_page_token => "",
:next_link => "",
- :items => @objects.as_api_response(:superuser)
+ :items => @objects.as_api_response(nil)
}
+ if @objects.respond_to? :except
+ @object_list[:items_available] = @objects.except(:limit).count
+ end
render json: @object_list
end
order: { type: 'string', required: false }
}
end
+
+ def client_accepts_plain_text_stream
+ (request.headers['Accept'].split(' ') &
+ ['text/plain', '*/*']).count > 0
+ end
+
+ def render *opts
+ response = opts.first[:json]
+ if response.is_a?(Hash) &&
+ params[:_profile] &&
+ Thread.current[:request_starttime]
+ response[:_profile] = {
+ request_time: Time.now - Thread.current[:request_starttime]
+ }
+ end
+ super *opts
+ end
end