]> git.openstreetmap.org Git - rails.git/blob - app/controllers/traces/data_controller.rb
Merge remote-tracking branch 'upstream/pull/5575'
[rails.git] / app / controllers / traces / data_controller.rb
1 module Traces
2   class DataController < ApplicationController
3     layout "site"
4
5     before_action :authorize_web
6     before_action :set_locale
7     before_action :check_database_readable
8
9     authorize_resource :class => Trace
10
11     before_action :offline_redirect
12
13     def show
14       trace = Trace.visible.find(params[:trace_id])
15
16       if trace.public? || (current_user && current_user == trace.user)
17         if Acl.no_trace_download(request.remote_ip)
18           head :forbidden
19         elsif request.format == Mime[:xml]
20           send_data(trace.xml_file.read, :filename => "#{trace.id}.xml", :type => request.format.to_s, :disposition => "attachment")
21         elsif request.format == Mime[:gpx]
22           send_data(trace.xml_file.read, :filename => "#{trace.id}.gpx", :type => request.format.to_s, :disposition => "attachment")
23         elsif trace.file.attached?
24           redirect_to rails_blob_path(trace.file, :disposition => "attachment")
25         else
26           send_file(trace.trace_name, :filename => "#{trace.id}#{trace.extension_name}", :type => trace.mime_type, :disposition => "attachment")
27         end
28       else
29         head :not_found
30       end
31     rescue ActiveRecord::RecordNotFound
32       head :not_found
33     end
34
35     private
36
37     def offline_redirect
38       render :template => "traces/offline" if Settings.status == "gpx_offline"
39     end
40   end
41 end