]> git.openstreetmap.org Git - rails.git/blob - app/controllers/old_node_controller.rb
Adding first cut of Redactions support
[rails.git] / app / controllers / old_node_controller.rb
1 class OldNodeController < 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   before_filter :check_api_writable, :only => [ :redact ]
9   after_filter :compress_output
10   around_filter :api_call_handle_error, :api_call_timeout
11
12   def history
13     # TODO - maybe a bit heavyweight to do this on every
14     # call, perhaps try lazy auth.
15     setup_user_auth
16
17     node = Node.find(params[:id].to_i)
18     
19     doc = OSM::API.new.get_xml_doc
20     
21     node.old_nodes.each do |old_node|
22       unless old_node.redacted? and (@user.nil? or not @user.moderator?)
23         doc.root << old_node.to_xml_node
24       end
25     end
26     
27     render :text => doc.to_s, :content_type => "text/xml"
28   end
29   
30   def version
31     if old_node = OldNode.where(:node_id => params[:id], :version => params[:version]).first
32       # TODO - maybe a bit heavyweight to do this on every
33       # call, perhaps try lazy auth.
34       setup_user_auth
35       
36       if old_node.redacted? and (@user.nil? or not @user.moderator?)
37         render :nothing => true, :status => :forbidden
38       else
39
40         response.last_modified = old_node.timestamp
41         
42         doc = OSM::API.new.get_xml_doc
43         doc.root << old_node.to_xml_node
44         
45         render :text => doc.to_s, :content_type => "text/xml"
46       end
47     else
48       render :nothing => true, :status => :not_found
49     end
50   end
51
52   def redact
53     if @user && @user.moderator?
54       render :nothing => true
55
56     else
57       render :nothing => true, :status => :forbidden
58     end
59   end
60 end