Make api show/update/destroy way actions resourceful
This commit is contained in:
parent
3b0be171b9
commit
35fc840b41
4 changed files with 11 additions and 13 deletions
|
@ -38,8 +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, :destroy], [Node] if scope?(token, :write_api)
|
||||
can [:create, :update, :delete], [Way, Relation] if scope?(token, :write_api)
|
||||
can [:create, :update, :destroy], [Node, Way] if scope?(token, :write_api)
|
||||
can [:create, :update, :delete], [Relation] if scope?(token, :write_api)
|
||||
end
|
||||
|
||||
if user.moderator?
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
module Api
|
||||
class WaysController < 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]
|
||||
|
||||
def index
|
||||
raise OSM::APIBadUserInput, "The parameter ways is required, and must be of the form ways=id[,id[,id...]]" unless params["ways"]
|
||||
|
@ -60,7 +60,7 @@ module Api
|
|||
end
|
||||
|
||||
# This is the API call to delete a way
|
||||
def delete
|
||||
def destroy
|
||||
way = Way.find(params[:id])
|
||||
new_way = Way.from_xml(request.raw_post)
|
||||
|
||||
|
|
|
@ -41,9 +41,6 @@ OpenStreetMap::Application.routes.draw do
|
|||
get "way/:id/relations" => "relations#relations_for_way", :as => :way_relations, :id => /\d+/
|
||||
post "way/:id/:version/redact" => "old_ways#redact", :as => :way_version_redact, :version => /\d+/, :id => /\d+/
|
||||
get "way/:id/:version" => "old_ways#show", :as => :api_old_way, :id => /\d+/, :version => /\d+/
|
||||
get "way/:id" => "ways#show", :as => :api_way, :id => /\d+/
|
||||
put "way/:id" => "ways#update", :id => /\d+/
|
||||
delete "way/:id" => "ways#delete", :id => /\d+/
|
||||
|
||||
get "relation/:id/relations" => "relations#relations_for_relation", :as => :relation_relations, :id => /\d+/
|
||||
get "relation/:id/history" => "old_relations#history", :as => :api_relation_history, :id => /\d+/
|
||||
|
@ -61,6 +58,7 @@ OpenStreetMap::Application.routes.draw do
|
|||
put "node/create" => "nodes#create", :as => nil
|
||||
|
||||
resources :ways, :only => [:index, :create]
|
||||
resources :ways, :path => "way", :id => /\d+/, :only => [:show, :update, :destroy]
|
||||
put "way/create" => "ways#create", :as => nil
|
||||
|
||||
resources :relations, :only => [:index, :create]
|
||||
|
|
|
@ -39,7 +39,7 @@ module Api
|
|||
)
|
||||
assert_routing(
|
||||
{ :path => "/api/0.6/way/1", :method => :delete },
|
||||
{ :controller => "api/ways", :action => "delete", :id => "1" }
|
||||
{ :controller => "api/ways", :action => "destroy", :id => "1" }
|
||||
)
|
||||
|
||||
assert_recognizes(
|
||||
|
@ -284,7 +284,7 @@ module Api
|
|||
# Test deleting ways.
|
||||
# -------------------------------------
|
||||
|
||||
def test_delete
|
||||
def test_destroy
|
||||
private_user = create(:user, :data_public => false)
|
||||
private_open_changeset = create(:changeset, :user => private_user)
|
||||
private_closed_changeset = create(:changeset, :closed, :user => private_user)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue