]> git.openstreetmap.org Git - rails.git/commitdiff
Make api show/update/destroy node actions resourceful
authorAnton Khorev <tony29@yandex.ru>
Sat, 1 Feb 2025 11:01:01 +0000 (14:01 +0300)
committerAnton Khorev <tony29@yandex.ru>
Wed, 5 Feb 2025 17:22:16 +0000 (20:22 +0300)
app/abilities/api_ability.rb
app/controllers/api/nodes_controller.rb
config/routes.rb
test/controllers/api/nodes_controller_test.rb

index 13a453eb59305e2a8b485994abd19ea66f0bbf8c..e3ea9e4345a793290ff9e75293d56a5a1bdf43ef 100644 (file)
@@ -38,7 +38,8 @@ class ApiAbility
         if user.terms_agreed?
           can [:create, :update, :upload, :close, :subscribe, :unsubscribe], Changeset if scope?(token, :write_api)
           can :create, ChangesetComment if scope?(token, :write_api)
-          can [:create, :update, :delete], [Node, Way, Relation] if scope?(token, :write_api)
+          can [:create, :update, :destroy], [Node] if scope?(token, :write_api)
+          can [:create, :update, :delete], [Way, Relation] if scope?(token, :write_api)
         end
 
         if user.moderator?
index 6477271d4e890788f3c260775cd27a3c3ad53a88..b7165b2fe69039342a3594f6bd4c5126075a8101 100644 (file)
@@ -2,14 +2,14 @@
 
 module Api
   class NodesController < ApiController
-    before_action :check_api_writable, :only => [:create, :update, :delete]
-    before_action :authorize, :only => [:create, :update, :delete]
+    before_action :check_api_writable, :only => [:create, :update, :destroy]
+    before_action :authorize, :only => [:create, :update, :destroy]
 
     authorize_resource
 
-    before_action :require_public_data, :only => [:create, :update, :delete]
-    before_action :set_request_formats, :except => [:create, :update, :delete]
-    before_action :check_rate_limit, :only => [:create, :update, :delete]
+    before_action :require_public_data, :only => [:create, :update, :destroy]
+    before_action :set_request_formats, :except => [:create, :update, :destroy]
+    before_action :check_rate_limit, :only => [:create, :update, :destroy]
 
     # Dump the details on many nodes whose ids are given in the "nodes" parameter.
     def index
@@ -68,7 +68,7 @@ module Api
     # Delete a node. Doesn't actually delete it, but retains its history
     # in a wiki-like way. We therefore treat it like an update, so the delete
     # method returns the new version number.
-    def delete
+    def destroy
       node = Node.find(params[:id])
       new_node = Node.from_xml(request.raw_post)
 
index 2ba9bdb932bff078826ee89e335746f8daf3589a..0d6a51ad9f79f279fd039e27db9669f3e9fc4a1c 100644 (file)
@@ -35,9 +35,6 @@ OpenStreetMap::Application.routes.draw do
     get "node/:id/history" => "old_nodes#history", :as => :api_node_history, :id => /\d+/
     post "node/:id/:version/redact" => "old_nodes#redact", :as => :node_version_redact, :version => /\d+/, :id => /\d+/
     get "node/:id/:version" => "old_nodes#show", :as => :api_old_node, :id => /\d+/, :version => /\d+/
-    get "node/:id" => "nodes#show", :as => :api_node, :id => /\d+/
-    put "node/:id" => "nodes#update", :id => /\d+/
-    delete "node/:id" => "nodes#delete", :id => /\d+/
 
     get "way/:id/history" => "old_ways#history", :as => :api_way_history, :id => /\d+/
     get "way/:id/full" => "ways#full", :as => :way_full, :id => /\d+/
@@ -60,6 +57,7 @@ OpenStreetMap::Application.routes.draw do
 
   namespace :api, :path => "api/0.6" do
     resources :nodes, :only => [:index, :create]
+    resources :nodes, :path => "node", :id => /\d+/, :only => [:show, :update, :destroy]
     put "node/create" => "nodes#create", :as => nil
 
     resources :ways, :only => [:index, :create]
index 04120dace129af8b096b11f2a273b9384f080dcd..6ec9085600572c39cbf367cc1797a09e18b839e4 100644 (file)
@@ -31,7 +31,7 @@ module Api
       )
       assert_routing(
         { :path => "/api/0.6/node/1", :method => :delete },
-        { :controller => "api/nodes", :action => "delete", :id => "1" }
+        { :controller => "api/nodes", :action => "destroy", :id => "1" }
       )
 
       assert_recognizes(
@@ -218,7 +218,7 @@ module Api
 
     # this tests deletion restrictions - basic deletion is tested in the unit
     # tests for node!
-    def test_delete
+    def test_destroy
       private_user = create(:user, :data_public => false)
       private_user_changeset = create(:changeset, :user => private_user)
       private_user_closed_changeset = create(:changeset, :closed, :user => private_user)