2   class WaysController < ApiController
 
   5     before_action :check_api_writable, :only => [:create, :update, :delete]
 
   6     before_action :check_api_readable, :except => [:create, :update, :delete]
 
   7     before_action :authorize, :only => [:create, :update, :delete]
 
  11     before_action :require_public_data, :only => [:create, :update, :delete]
 
  12     around_action :api_call_handle_error, :api_call_timeout
 
  14     before_action :set_request_formats, :except => [:create, :update, :delete]
 
  17       raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]" unless params["ways"]
 
  19       ids = params["ways"].split(",").collect(&:to_i)
 
  21       raise OSM::APIBadUserInput, "No ways were given to search for" if ids.empty?
 
  26       respond_to do |format|
 
  33       @way = Way.find(params[:id])
 
  35       response.last_modified = @way.timestamp
 
  39         respond_to do |format|
 
  51       way = Way.from_xml(request.raw_post, :create => true)
 
  53       # Assume that Way.from_xml has thrown an exception if there is an error parsing the xml
 
  54       way.create_with_history current_user
 
  55       render :plain => way.id.to_s
 
  59       way = Way.find(params[:id])
 
  60       new_way = Way.from_xml(request.raw_post)
 
  62       raise OSM::APIBadUserInput, "The id in the url (#{way.id}) is not the same as provided in the xml (#{new_way.id})" unless new_way && new_way.id == way.id
 
  64       way.update_from(new_way, current_user)
 
  65       render :plain => way.version.to_s
 
  68     # This is the API call to delete a way
 
  70       way = Way.find(params[:id])
 
  71       new_way = Way.from_xml(request.raw_post)
 
  73       if new_way && new_way.id == way.id
 
  74         way.delete_with_history!(new_way, current_user)
 
  75         render :plain => way.version.to_s
 
  82       @way = Way.includes(:nodes => :node_tags).find(params[:id])
 
  89         @way.nodes.uniq.each do |node|
 
  92             visible_nodes[node.id] = node
 
  97         respond_to do |format|
 
 107     # returns all the ways which are currently using the node given in the
 
 108     # :id parameter. note that this used to return deleted ways as well, but
 
 109     # this seemed not to be the expected behaviour, so it was removed.
 
 111       wayids = WayNode.where(:node_id => params[:id]).collect { |ws| ws.id[0] }.uniq
 
 113       @ways = Way.where(:id => wayids, :visible => true)
 
 116       respond_to do |format|