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)
19 node.user_id = @user.id
21 node.save_with_history!
23 render :text => node.id.to_s, :content_type => "text/plain"
25 render :nothing => true, :status => :bad_request
28 render :nothing => true, :status => :method_not_allowed
32 # Dump the details on a node given in params[:id]
35 node = Node.find(params[:id])
37 response.headers['Last-Modified'] = node.timestamp.rfc822
38 render :text => node.to_xml.to_s, :content_type => "text/xml"
40 render :text => "", :status => :gone
42 rescue ActiveRecord::RecordNotFound
43 render :nothing => true, :status => :not_found
47 # Update a node from given XML
50 node = Node.find(params[:id])
51 new_node = Node.from_xml(request.raw_post)
53 if new_node and new_node.id == node.id
54 node.user_id = @user.id
55 node.latitude = new_node.latitude
56 node.longitude = new_node.longitude
57 node.tags = new_node.tags
59 node.save_with_history!
61 render :nothing => true
63 render :nothing => true, :status => :bad_request
65 rescue ActiveRecord::RecordNotFound
66 render :nothing => true, :status => :not_found
70 # Delete a node. Doesn't actually delete it, but retains its history in a wiki-like way.
71 # FIXME remove all the fricking SQL
74 node = Node.find(params[:id])
77 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 ])
78 render :text => "", :status => :precondition_failed
79 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]])
80 render :text => "", :status => :precondition_failed
82 node.user_id = @user.id
84 node.save_with_history!
86 render :nothing => true
89 render :text => "", :status => :gone
91 rescue ActiveRecord::RecordNotFound
92 render :nothing => true, :status => :not_found
98 ids = params['nodes'].split(',').collect { |n| n.to_i }
101 doc = OSM::API.new.get_xml_doc
103 Node.find(ids).each do |node|
104 doc.root << node.to_xml_node
107 render :text => doc.to_s, :content_type => "text/xml"
109 render :nothing => true, :status => :bad_request