1 # The NodeController is the RESTful interface to Node objects
3 class NodeController < ApplicationController
7 before_filter :authorize, :only => [:create, :update, :delete]
8 before_filter :check_write_availability, :only => [:create, :update, :delete]
9 before_filter :check_read_availability, :except => [:create, :update, :delete]
10 after_filter :compress_output
12 # Create a node from XML.
15 node = Node.from_xml(request.raw_post, true)
18 node.user_id = @user.id
20 node.save_with_history!
22 render :text => node.id.to_s, :content_type => "text/plain"
24 render :nothing => true, :status => :bad_request
27 render :nothing => true, :status => :method_not_allowed
31 # Dump the details on a node given in params[:id]
34 node = Node.find(params[:id])
36 response.headers['Last-Modified'] = node.timestamp.rfc822
37 render :text => node.to_xml.to_s, :content_type => "text/xml"
39 render :text => "", :status => :gone
41 rescue ActiveRecord::RecordNotFound
42 render :nothing => true, :status => :not_found
46 # Update a node from given XML
49 node = Node.find(params[:id])
50 new_node = Node.from_xml(request.raw_post)
52 if new_node and new_node.id == node.id
53 node.user_id = @user.id
54 node.latitude = new_node.latitude
55 node.longitude = new_node.longitude
56 node.tags = new_node.tags
58 node.save_with_history!
60 render :nothing => true
62 render :nothing => true, :status => :bad_request
64 rescue ActiveRecord::RecordNotFound
65 render :nothing => true, :status => :not_found
69 # Delete a node. Doesn't actually delete it, but retains its history in a wiki-like way.
70 # FIXME remove all the fricking SQL
73 node = Node.find(params[:id])
76 if WayNode.find(:first, :joins => "INNER JOIN current_ways ON current_ways.id = current_way_nodes.id", :conditions => [ "current_ways.visible = 1 AND current_way_nodes.node_id = ?", node.id ])
77 render :text => "", :status => :precondition_failed
78 elsif RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='node' and member_id=?", params[:id]])
79 render :text => "", :status => :precondition_failed
81 node.user_id = @user.id
83 node.save_with_history!
85 render :nothing => true
88 render :text => "", :status => :gone
90 rescue ActiveRecord::RecordNotFound
91 render :nothing => true, :status => :not_found
97 ids = params['nodes'].split(',').collect { |n| n.to_i }
100 doc = OSM::API.new.get_xml_doc
102 Node.find(ids).each do |node|
103 doc.root << node.to_xml_node
106 render :text => doc.to_s, :content_type => "text/xml"
108 render :nothing => true, :status => :bad_request