]> git.openstreetmap.org Git - rails.git/blob - app/controllers/old_way_controller.rb
fc7366bb6657e3745c279f8cd6c5c4cd19d5d462
[rails.git] / app / controllers / old_way_controller.rb
1 class OldWayController < ApplicationController
2   require 'xml/libxml'
3
4   skip_before_filter :verify_authenticity_token
5   before_filter :authorize, :only => [ :redact ]
6   before_filter :require_allow_write_api, :only => [ :redact ]
7   before_filter :check_api_readable
8   after_filter :compress_output
9   around_filter :api_call_handle_error, :api_call_timeout
10
11   def history
12     way = Way.find(params[:id])
13
14     # TODO - maybe a bit heavyweight to do this on every
15     # call, perhaps try lazy auth.
16     setup_user_auth
17     
18     doc = OSM::API.new.get_xml_doc
19     
20     way.old_ways.each do |old_way|
21       unless old_way.redacted? and (@user.nil? or not @user.moderator?) and not params[:show_redactions] == "true"
22         doc.root << old_way.to_xml_node
23       end
24     end
25     
26     render :text => doc.to_s, :content_type => "text/xml"
27   end
28   
29   def version
30     if old_way = OldWay.where(:way_id => params[:id], :version => params[:version]).first
31       # TODO - maybe a bit heavyweight to do this on every
32       # call, perhaps try lazy auth.
33       setup_user_auth
34
35       if old_way.redacted? and (@user.nil? or not @user.moderator?) and not params[:show_redactions] == "true"
36         render :nothing => true, :status => :forbidden
37       else
38         response.last_modified = old_way.timestamp
39         
40         doc = OSM::API.new.get_xml_doc
41         doc.root << old_way.to_xml_node
42         
43         render :text => doc.to_s, :content_type => "text/xml"
44       end
45     else
46       render :nothing => true, :status => :not_found
47     end
48   end
49
50   def redact
51     if @user && @user.moderator?
52       render :nothing => true
53
54     else
55       render :nothing => true, :status => :forbidden
56     end
57   end
58 end