]> git.openstreetmap.org Git - rails.git/commitdiff
prevent update of any object without providing the correct/current
authorChristopher Schmidt <crschmidt@crschmidt.net>
Sun, 11 May 2008 21:49:33 +0000 (21:49 +0000)
committerChristopher Schmidt <crschmidt@crschmidt.net>
Sun, 11 May 2008 21:49:33 +0000 (21:49 +0000)
version as part of the XML. This affects update-only at this time:
DELETE doesn't work the same way because we don't provide the data as
part of a DELETE

app/controllers/node_controller.rb
app/controllers/relation_controller.rb
app/controllers/way_controller.rb

index 956a8b8d9e10a50532c98863fbfbd38922777f5c..fa6759c3b5debb59e601a7bd519d401ac352dfd9 100644 (file)
@@ -49,6 +49,10 @@ class NodeController < ApplicationController
     begin
       node = Node.find(params[:id])
       new_node = Node.from_xml(request.raw_post)
+      if new_node.version != node.version
+        render :text => "Version mismatch: Provided " + new_node.version.to_s + ", server had: " + node.version.to_s, :status => :bad_request
+        return
+      end  
 
       if new_node and new_node.id == node.id
         node.update_from(new_node, @user)
index 20f5372a6cc1ed0e40d64c37ece71f6a1b7bc738..d7b9de13cb6589cad3589e68396648ca7193b001 100644 (file)
@@ -49,6 +49,10 @@ class RelationController < ApplicationController
     begin
       relation = Relation.find(params[:id])
       new_relation = Relation.from_xml(request.raw_post)
+      if new_relation.version != relation.version
+        render :text => "Version mismatch: Provided " + new_relation.version.to_s + ", server had: " + relation.version.to_s, :status => :bad_request
+        return
+      end  
 
       if new_relation and new_relation.id == relation.id
        relation.update_from new_relation, user
index 94a10d4242778335bf1043a2c26d71a9b86f37d4..d3a1b039f557b2afc129f050106b5282db23b897 100644 (file)
@@ -49,6 +49,11 @@ class WayController < ApplicationController
     begin
       way = Way.find(params[:id])
       new_way = Way.from_xml(request.raw_post)
+      if new_way.version != way.version
+        render :text => "Version mismatch: Provided " + new_way.version.to_s + ", server had: " + way.version.to_s, :status => :bad_request
+        return
+      end  
+        
 
       if new_way and new_way.id == way.id
         way.update_from(new_way, @user)