]> git.openstreetmap.org Git - rails.git/blob - app/controllers/old_controller.rb
Decided that restricting redacts to the user who created the
[rails.git] / app / controllers / old_controller.rb
1 # this class pulls together the logic for all the old_* controllers
2 # into one place. as it turns out, the API methods for historical
3 # nodes, ways and relations are basically identical.
4 class OldController < ApplicationController
5   require 'xml/libxml'
6
7   skip_before_filter :verify_authenticity_token
8   before_filter :setup_user_auth, :only => [ :history, :version ]
9   before_filter :authorize, :only => [ :redact ]
10   before_filter :authorize_moderator, :only => [ :redact ]
11   before_filter :require_allow_write_api, :only => [ :redact ]
12   before_filter :check_api_readable
13   before_filter :check_api_writable, :only => [ :redact ]
14   after_filter :compress_output
15   around_filter :api_call_handle_error, :api_call_timeout
16   before_filter :lookup_old_element, :except => [ :history ]
17   before_filter :lookup_old_elements_via_current, :only => [ :history ]
18
19   def history
20     doc = OSM::API.new.get_xml_doc
21     
22     visible_elements = if show_redactions?
23                          @elements
24                        else
25                          @elements.unredacted
26                        end
27
28     visible_elements.each do |element|
29       doc.root << element.to_xml_node
30     end
31     
32     render :text => doc.to_s, :content_type => "text/xml"
33   end
34   
35   def version
36     if @old_element.redacted? and not show_redactions?
37       render :nothing => true, :status => :forbidden
38
39     else
40       response.last_modified = @old_element.timestamp
41       
42       doc = OSM::API.new.get_xml_doc
43       doc.root << @old_element.to_xml_node
44         
45       render :text => doc.to_s, :content_type => "text/xml"
46     end
47   end
48
49   def redact
50     redaction_id = params['redaction']
51     unless redaction_id.nil?
52       # if a redaction ID was specified, then set this element to
53       # be redacted in that redaction.
54       redaction = Redaction.find(redaction_id.to_i)
55       @old_element.redact!(redaction)
56       
57     else
58       # if no redaction ID was provided, then this is an unredact
59       # operation.
60       @old_element.redact!(nil)
61     end
62     
63     # just return an empty 200 OK for success
64     render :nothing => true
65   end
66
67   private
68   
69   def show_redactions?
70     @user and @user.moderator? and params[:show_redactions] == "true"
71   end
72 end