1 class WayController < ApplicationController
4 skip_before_action :verify_authenticity_token
5 before_action :authorize, :only => [:create, :update, :delete]
6 before_action :require_allow_write_api, :only => [:create, :update, :delete]
7 before_action :require_public_data, :only => [:create, :update, :delete]
8 before_action :check_api_writable, :only => [:create, :update, :delete]
9 before_action :check_api_readable, :except => [:create, :update, :delete]
10 around_action :api_call_handle_error, :api_call_timeout
15 way = Way.from_xml(request.raw_post, true)
17 # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
18 way.create_with_history @user
19 render :text => way.id.to_s, :content_type => "text/plain"
23 way = Way.find(params[:id])
25 response.last_modified = way.timestamp
28 render :text => way.to_xml.to_s, :content_type => "text/xml"
30 render :text => "", :status => :gone
35 way = Way.find(params[:id])
36 new_way = Way.from_xml(request.raw_post)
38 unless new_way && new_way.id == way.id
39 fail OSM::APIBadUserInput.new("The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})")
42 way.update_from(new_way, @user)
43 render :text => way.version.to_s, :content_type => "text/plain"
46 # This is the API call to delete a way
48 way = Way.find(params[:id])
49 new_way = Way.from_xml(request.raw_post)
51 if new_way && new_way.id == way.id
52 way.delete_with_history!(new_way, @user)
53 render :text => way.version.to_s, :content_type => "text/plain"
55 render :text => "", :status => :bad_request
60 way = Way.includes(:nodes => :node_tags).find(params[:id])
65 user_display_name_cache = {}
67 doc = OSM::API.new.get_xml_doc
68 way.nodes.uniq.each do |node|
70 doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
71 visible_nodes[node.id] = node
74 doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
76 render :text => doc.to_s, :content_type => "text/xml"
78 render :text => "", :status => :gone
84 fail OSM::APIBadUserInput.new("The parameter ways is required, and must be of the form ways=id[,id[,id...]]")
87 ids = params["ways"].split(",").collect(&:to_i)
90 fail OSM::APIBadUserInput.new("No ways were given to search for")
93 doc = OSM::API.new.get_xml_doc
95 Way.find(ids).each do |way|
96 doc.root << way.to_xml_node
99 render :text => doc.to_s, :content_type => "text/xml"
103 # returns all the ways which are currently using the node given in the
104 # :id parameter. note that this used to return deleted ways as well, but
105 # this seemed not to be the expected behaviour, so it was removed.
107 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
109 doc = OSM::API.new.get_xml_doc
111 Way.find(wayids).each do |way|
112 doc.root << way.to_xml_node if way.visible
115 render :text => doc.to_s, :content_type => "text/xml"