]> git.openstreetmap.org Git - rails.git/blob - app/controllers/traces/pictures_controller.rb
e190621674df094aabc4bca32c1c6ac1d5ec16c0
[rails.git] / app / controllers / traces / pictures_controller.rb
1 module Traces
2   class PicturesController < ApplicationController
3     before_action :authorize_web
4     before_action :check_database_readable
5
6     authorize_resource :trace
7
8     def show
9       trace = Trace.visible.imported.find(params[:trace_id])
10
11       if trace.public? || (current_user && current_user == trace.user)
12         if trace.icon.attached?
13           redirect_to rails_blob_path(trace.image, :disposition => "inline")
14         else
15           expires_in 7.days, :private => !trace.public?, :public => trace.public?
16           send_file(trace.large_picture_name, :filename => "#{trace.id}.gif", :type => "image/gif", :disposition => "inline")
17         end
18       else
19         head :forbidden
20       end
21     rescue ActiveRecord::RecordNotFound
22       head :not_found
23     end
24   end
25 end