X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/9189093997610a8f289037d37b683c9fed060ae1..332bcb6b181109d56fc8b30ae78ade3961849a83:/app/controllers/segment_controller.rb diff --git a/app/controllers/segment_controller.rb b/app/controllers/segment_controller.rb index 5f2603f0b..a75ff911d 100644 --- a/app/controllers/segment_controller.rb +++ b/app/controllers/segment_controller.rb @@ -5,23 +5,28 @@ class SegmentController < ApplicationController after_filter :compress_output def create - response.headers["Content-Type"] = 'application/xml' + response.headers["Content-Type"] = 'text/xml' if request.put? segment = Segment.from_xml(request.raw_post, true) if segment - segment.user_id = @user.id segment.from_node = Node.find(segment.node_a.to_i) segment.to_node = Node.find(segment.node_b.to_i) + + if segment.from_node == segment.to_node + render :nothing => true, :status => HTTP_EXPECTATION_FAILED + return + end - unless segment.precondtions_ok? # are the nodes visible? - render :nothing => true, :status => 412 + unless segment.preconditions_ok? # are the nodes visible? + render :nothing => true, :status => HTTP_PRECONDITION_FAILED + return end if segment.save_with_history - render :text => segment.id + render :text => segment.id.to_s else render :nothing => true, :status => 500 end @@ -37,7 +42,7 @@ class SegmentController < ApplicationController end def rest - response.headers["Content-Type"] = 'application/xml' + response.headers["Content-Type"] = 'text/xml' unless Segment.exists?(params[:id]) render :nothing => true, :status => 404 return @@ -66,13 +71,19 @@ class SegmentController < ApplicationController segment.timestamp = Time.now segment.user_id = @user.id + if new_segment.node_a == new_segment.node_b + render :nothing => true, :status => HTTP_EXPECTATION_FAILED + return + end + segment.node_a = new_segment.node_a segment.node_b = new_segment.node_b + segment.tags = new_segment.tags segment.visible = new_segment.visible if segment.id == new_segment.id and segment.save_with_history - render :nothing => true, :status => 200 + render :nothing => true, :status => HTTP_OK else render :nothing => true, :status => 500 end @@ -82,11 +93,11 @@ class SegmentController < ApplicationController end def segments - response.headers["Content-Type"] = 'application/xml' + response.headers["Content-Type"] = 'text/xml' ids = params['segments'].split(',').collect {|s| s.to_i } if ids.length > 0 segmentlist = Segment.find(ids) - doc = get_xml_doc + doc = OSM::API.get_xml_doc segmentlist.each do |segment| doc.root << segment.to_xml_node end