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