2 class WaysController < ApplicationController
5 skip_before_action :verify_authenticity_token
6 before_action :authorize, :only => [:create, :update, :delete]
7 before_action :api_deny_access_handler
11 before_action :require_public_data, :only => [:create, :update, :delete]
12 before_action :check_api_writable, :only => [:create, :update, :delete]
13 before_action :check_api_readable, :except => [:create, :update, :delete]
14 around_action :api_call_handle_error, :api_call_timeout
19 way = Way.from_xml(request.raw_post, true)
21 # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
22 way.create_with_history current_user
23 render :plain => way.id.to_s
27 way = Way.find(params[:id])
29 response.last_modified = way.timestamp
32 render :xml => way.to_xml.to_s
39 way = Way.find(params[:id])
40 new_way = Way.from_xml(request.raw_post)
42 unless new_way && new_way.id == way.id
43 raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})"
46 way.update_from(new_way, current_user)
47 render :plain => way.version.to_s
50 # This is the API call to delete a way
52 way = Way.find(params[:id])
53 new_way = Way.from_xml(request.raw_post)
55 if new_way && new_way.id == way.id
56 way.delete_with_history!(new_way, current_user)
57 render :plain => way.version.to_s
64 way = Way.includes(:nodes => :node_tags).find(params[:id])
69 user_display_name_cache = {}
71 doc = OSM::API.new.get_xml_doc
72 way.nodes.uniq.each do |node|
74 doc.root << node.to_xml_node(changeset_cache, user_display_name_cache)
75 visible_nodes[node.id] = node
78 doc.root << way.to_xml_node(visible_nodes, changeset_cache, user_display_name_cache)
80 render :xml => doc.to_s
88 raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]"
91 ids = params["ways"].split(",").collect(&:to_i)
93 raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
95 doc = OSM::API.new.get_xml_doc
97 Way.find(ids).each do |way|
98 doc.root << way.to_xml_node
101 render :xml => doc.to_s
105 # returns all the ways which are currently using the node given in the
106 # :id parameter. note that this used to return deleted ways as well, but
107 # this seemed not to be the expected behaviour, so it was removed.
109 wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
111 doc = OSM::API.new.get_xml_doc
113 Way.find(wayids).each do |way|
114 doc.root << way.to_xml_node if way.visible
117 render :xml => doc.to_s