X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/5ed2cbce027175963312c34ed3bb00cde4f5a66f..7a216c0ce66e0426613415d887937be729cb26d2:/app/controllers/node_controller.rb diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 9f8f4a38b..956a8b8d9 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -15,7 +15,7 @@ class NodeController < ApplicationController node = Node.from_xml(request.raw_post, true) if node - node.version = 0 + node.version = 0 node.user_id = @user.id node.visible = true node.save_with_history! @@ -51,14 +51,8 @@ class NodeController < ApplicationController new_node = Node.from_xml(request.raw_post) if new_node and new_node.id == node.id - node.user_id = @user.id - node.latitude = new_node.latitude - node.longitude = new_node.longitude - node.tags = new_node.tags - node.visible = true - node.save_with_history! - - render :nothing => true + node.update_from(new_node, @user) + render :text => node.version.to_s, :content_type => "text/plain" else render :nothing => true, :status => :bad_request end @@ -72,24 +66,13 @@ class NodeController < ApplicationController def delete begin node = Node.find(params[:id]) - - if node.visible - 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 ]) - render :text => "", :status => :precondition_failed - 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]]) - render :text => "", :status => :precondition_failed - else - node.user_id = @user.id - node.visible = 0 - node.save_with_history! - - render :nothing => true - end - else - render :text => "", :status => :gone - end + node.delete_with_history(@user) rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found + rescue OSM::APIAlreadyDeletedError + render :text => "", :status => :gone + rescue OSM::APIPreconditionFailedError + render :text => "", :status => :precondition_failed end end