]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/node_controller.rb
Provide both HTML and plain text versions of account confirmation and
[rails.git] / app / controllers / node_controller.rb
index 7a841769b9df77f997972bcb7d26a6d79ba3ec22..0a3897fe9986da7318dafd557c84949a91b8020e 100644 (file)
@@ -1,7 +1,10 @@
 class NodeController < ApplicationController
   require 'xml/libxml'
 
-  before_filter :authorize, :only => [:create, :update, :destroy]
+  session :off
+  before_filter :authorize, :only => [:create, :update, :delete]
+  before_filter :check_write_availability, :only => [:create, :update, :delete]
+  before_filter :check_read_availability, :except => [:create, :update, :delete]
   after_filter :compress_output
 
   def create
@@ -11,12 +14,9 @@ class NodeController < ApplicationController
       if node
         node.user_id = @user.id
         node.visible = true
+        node.save_with_history!
 
-        if node.save_with_history
-          render :text => node.id.to_s, :content_type => "text/plain"
-        else
-          render :nothing => true, :status => :internal_server_error
-        end
+        render :text => node.id.to_s, :content_type => "text/plain"
       else
         render :nothing => true, :status => :bad_request
       end
@@ -36,8 +36,6 @@ class NodeController < ApplicationController
       end
     rescue ActiveRecord::RecordNotFound
       render :nothing => true, :status => :not_found
-    rescue
-      render :nothing => true, :status => :internal_server_error
     end
   end
 
@@ -49,18 +47,13 @@ class NodeController < ApplicationController
         new_node = Node.from_xml(request.raw_post)
 
         if new_node and new_node.id == node.id
-          node.timestamp = Time.now
           node.user_id = @user.id
-
           node.latitude = new_node.latitude 
           node.longitude = new_node.longitude
           node.tags = new_node.tags
+          node.save_with_history!
 
-          if node.save_with_history
-            render :nothing => true
-          else
-            render :nothing => true, :status => :internal_server_error
-          end
+          render :nothing => true
         else
           render :nothing => true, :status => :bad_request
         end
@@ -69,8 +62,6 @@ class NodeController < ApplicationController
       end
     rescue ActiveRecord::RecordNotFound
       render :nothing => true, :status => :not_found
-    rescue
-      render :nothing => true, :status => :internal_server_error
     end
   end
 
@@ -84,7 +75,8 @@ class NodeController < ApplicationController
         else
           node.user_id = @user.id
           node.visible = 0
-          node.save_with_history
+          node.save_with_history!
+
           render :nothing => true
         end
       else
@@ -92,8 +84,6 @@ class NodeController < ApplicationController
       end
     rescue ActiveRecord::RecordNotFound
       render :nothing => true, :status => :not_found
-    rescue
-      render :nothing => true, :status => :internal_server_error
     end
   end