1 class WayController < ApplicationController
5 before_filter :authorize, :only => [:create, :update, :delete]
6 before_filter :check_write_availability, :only => [:create, :update, :delete]
7 before_filter :check_read_availability, :except => [:create, :update, :delete]
8 after_filter :compress_output
12 way = Way.from_xml(request.raw_post, true)
15 if !way.preconditions_ok?
16 render :text => "", :status => :precondition_failed
18 way.user_id = @user.id
19 way.save_with_history!
21 render :text => way.id.to_s, :content_type => "text/plain"
24 render :nothing => true, :status => :bad_request
27 render :nothing => true, :status => :method_not_allowed
33 way = Way.find(params[:id])
35 response.headers['Last-Modified'] = way.timestamp.rfc822
38 render :text => way.to_xml.to_s, :content_type => "text/xml"
40 render :text => "", :status => :gone
42 rescue ActiveRecord::RecordNotFound
43 render :nothing => true, :status => :not_found
49 way = Way.find(params[:id])
50 new_way = Way.from_xml(request.raw_post)
52 if new_way and new_way.id == way.id
53 if !new_way.preconditions_ok?
54 render :text => "", :status => :precondition_failed
56 way.user_id = @user.id
57 way.tags = new_way.tags
60 way.save_with_history!
62 render :nothing => true
65 render :nothing => true, :status => :bad_request
67 rescue ActiveRecord::RecordNotFound
68 render :nothing => true, :status => :not_found
74 way = Way.find(params[:id])
78 if RelationMember.find(:first, :joins => "INNER JOIN current_relations ON current_relations.id=current_relation_members.id", :conditions => [ "visible = 1 AND member_type='way' and member_id=?", params[:id]])
79 render :text => "", :status => :precondition_failed
81 way.user_id = @user.id
85 way.save_with_history!
87 render :nothing => true
90 render :text => "", :status => :gone
92 rescue ActiveRecord::RecordNotFound
93 render :nothing => true, :status => :not_found
101 way = Way.find(params[:id])
104 nd_ids = way.nds + [-1]
105 nodes = Node.find(:all, :conditions => "visible = 1 AND id IN (#{nd_ids.join(',')})")
108 doc = OSM::API.new.get_xml_doc
110 doc.root << node.to_xml_node()
112 doc.root << way.to_xml_node()
114 render :text => doc.to_s, :content_type => "text/xml"
116 render :text => "", :status => :gone
118 rescue ActiveRecord::RecordNotFound
119 render :nothing => true, :status => :not_found
125 ids = params['ways'].split(',').collect { |w| w.to_i }
131 doc = OSM::API.new.get_xml_doc
133 Way.find(ids).each do |way|
134 doc.root << way.to_xml_node
137 render :text => doc.to_s, :content_type => "text/xml"
139 render :nothing => true, :status => :bad_request
144 wayids = WayNode.find(:all, :conditions => ['node_id = ?', params[:id]]).collect { |ws| ws.id }.uniq
146 doc = OSM::API.new.get_xml_doc
148 Way.find(wayids).each do |way|
149 doc.root << way.to_xml_node
152 render :text => doc.to_s, :content_type => "text/xml"