]> git.openstreetmap.org Git - rails.git/commitdiff
Set params to sane defaults if unset by client.
authorThomas Wood <grand.edgemaster@gmail.com>
Fri, 23 Jan 2009 19:14:21 +0000 (19:14 +0000)
committerThomas Wood <grand.edgemaster@gmail.com>
Fri, 23 Jan 2009 19:14:21 +0000 (19:14 +0000)
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

index 47041b4919fb2e25de18c0fbfdc08a3c96b7c1ab..6528dffde1a862328f2a139021f0af24d373850f 100644 (file)
@@ -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