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)
18 way.create_with_history @user
19 render :text => way.id.to_s, :content_type => "text/plain"
21 render :text => "", :status => :bad_request
26 way = Way.find(params[:id])
28 response.last_modified = way.timestamp
31 render :text => way.to_xml.to_s, :content_type => "text/xml"
33 render :text => "", :status => :gone
38 way = Way.find(params[:id])
39 new_way = Way.from_xml(request.raw_post)
41 if new_way && new_way.id == way.id
42 way.update_from(new_way, @user)
43 render :text => way.version.to_s, :content_type => "text/plain"
45 render :text => "", :status => :bad_request
49 # This is the API call to delete a way
51 way = Way.find(params[:id])
52 new_way = Way.from_xml(request.raw_post)
54 if new_way && new_way.id == way.id
55 way.delete_with_history!(new_way, @user)
56 render :text => way.version.to_s, :content_type => "text/plain"
58 render :text => "", :status => :bad_request
63 way = Way.includes(:nodes => :node_tags).find(params[:id])
68 user_display_name_cache = {}
70 doc = OSM::API.new.get_xml_doc
71 way.nodes.uniq.each do |node|
73 doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
74 visible_nodes[node.id] = node
77 doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
79 render :text => doc.to_s, :content_type => "text/xml"
81 render :text => "", :status => :gone
87 fail OSM::APIBadUserInput.new("The parameter ways is required, and must be of the form ways=id[,id[,id...]]")
90 ids = params["ways"].split(",").collect(&:to_i)
93 fail OSM::APIBadUserInput.new("No ways were given to search for")
96 doc = OSM::API.new.get_xml_doc
98 Way.find(ids).each do |way|
99 doc.root << way.to_xml_node
102 render :text => doc.to_s, :content_type => "text/xml"
106 # returns all the ways which are currently using the node given in the
107 # :id parameter. note that this used to return deleted ways as well, but
108 # this seemed not to be the expected behaviour, so it was removed.
110 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
112 doc = OSM::API.new.get_xml_doc
114 Way.find(wayids).each do |way|
115 doc.root << way.to_xml_node if way.visible
118 render :text => doc.to_s, :content_type => "text/xml"