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.
5 class OldController < ApplicationController
8 skip_before_action :verify_authenticity_token
9 before_action :setup_user_auth, :only => [:history, :version]
10 before_action :api_deny_access_handler
11 before_action :authorize, :only => [:redact]
15 before_action :check_api_readable
16 before_action :check_api_writable, :only => [:redact]
17 around_action :api_call_handle_error, :api_call_timeout
18 before_action :lookup_old_element, :except => [:history]
19 before_action :lookup_old_element_versions, :only => [:history]
22 # the .where() method used in the lookup_old_element_versions
23 # call won't throw an error if no records are found, so we have
24 # to do that ourselves.
25 raise OSM::APINotFoundError if @elements.empty?
27 doc = OSM::API.new.get_xml_doc
29 visible_elements = if show_redactions?
35 visible_elements.each do |element|
36 doc.root << element.to_xml_node
39 render :xml => doc.to_s
43 if @old_element.redacted? && !show_redactions?
47 response.last_modified = @old_element.timestamp
49 doc = OSM::API.new.get_xml_doc
50 doc.root << @old_element.to_xml_node
52 render :xml => doc.to_s
57 redaction_id = params["redaction"]
59 # if no redaction ID was provided, then this is an unredact
61 @old_element.redact!(nil)
63 # if a redaction ID was specified, then set this element to
64 # be redacted in that redaction.
65 redaction = Redaction.find(redaction_id.to_i)
66 @old_element.redact!(redaction)
69 # just return an empty 200 OK for success
76 current_user&.moderator? && params[:show_redactions] == "true"