From 1522ed275c3efceb9629438e0272f2f2d4adf5ba Mon Sep 17 00:00:00 2001 From: Thomas Wood Date: Fri, 23 Jan 2009 19:14:21 +0000 Subject: [PATCH] Set params to sane defaults if unset by client. Reject creates with no file with 400, model validations will also reject with 400 (as was existing but broken behaviour) Closes #1510 --- app/controllers/trace_controller.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 47041b491..6528dffde 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -279,12 +279,20 @@ class TraceController < ApplicationController def api_create if request.post? - do_create(params[:file], params[:tags], params[:description], params[:public]) + tags = params[:tags] || "" + description = params[:description] || "" + pub = params[:public] || false + + if params[:file].respond_to?(:read) + do_create(params[:file], tags, description, pub) - if @trace.id - render :text => @trace.id.to_s, :content_type => "text/plain" - elsif @trace.valid? - render :nothing => true, :status => :internal_server_error + if @trace.id + render :text => @trace.id.to_s, :content_type => "text/plain" + elsif @trace.valid? + render :nothing => true, :status => :internal_server_error + else + render :nothing => true, :status => :bad_request + end else render :nothing => true, :status => :bad_request end -- 2.43.2