X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/16a641ac2a663ea926566a5cca2575ee295e8555..4d8ea0eed0d47b3547f222fbc47524328bbd23a7:/app/controllers/trace_controller.rb diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 7c5bd7db0..cf35d0046 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -83,14 +83,17 @@ class TraceController < ApplicationController def view @trace = Trace.find(params[:id]) - @title = "Viewing trace #{@trace.name}" - if !@trace.visible? - render :nothing => true, :status => :not_found - elsif !@trace.public? and @trace.user.id != @user.id - render :nothing => true, :status => :forbidden + + if @trace and @trace.visible? and + (@trace.public? or @trace.user.id == @user.id) + @title = "Viewing trace #{@trace.name}" + else + flash[:notice] = "Trace not found!" + redirect_to :controller => 'trace', :action => 'list' end rescue ActiveRecord::RecordNotFound - render :nothing => true, :status => :not_found + flash[:notice] = "Trace not found!" + redirect_to :controller => 'trace', :action => 'list' end def create @@ -121,7 +124,11 @@ class TraceController < ApplicationController trace = Trace.find(params[:id]) if trace.visible? and (trace.public? or (@user and @user == trace.user)) - send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment') + if request.format == Mime::XML + send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => Mime::XML.to_s, :disposition => 'attachment') + else + send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => 'attachment') + end else render :nothing, :status => :not_found end @@ -192,7 +199,7 @@ class TraceController < ApplicationController conditions[0] += " AND users.display_name = ?" conditions << params[:display_name] end - + if params[:tag] conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)" conditions << params[:tag] @@ -297,7 +304,7 @@ private @trace.timestamp = Time.now if @trace.save - File.rename(filename, @trace.trace_name) + FileUtils.mv(filename, @trace.trace_name) else FileUtils.rm_f(filename) end