Rename hide_comment and unhide_comment to destroy and restore

This preserves the API endpoints and HTTP methods, which could be changed in the next API version
This commit is contained in:
Andy Allan 2018-11-07 10:51:43 +01:00
parent 4b0d56f7e1
commit 04afeeb32f
3 changed files with 20 additions and 20 deletions

View file

@ -1,11 +1,11 @@
class ChangesetCommentsController < ApplicationController
before_action :authorize_web, :only => [:index]
before_action :set_locale, :only => [:index]
before_action :authorize, :only => [:create, :hide_comment, :unhide_comment]
before_action :require_moderator, :only => [:hide_comment, :unhide_comment]
before_action :require_allow_write_api, :only => [:create, :hide_comment, :unhide_comment]
before_action :authorize, :only => [:create, :destroy, :restore]
before_action :require_moderator, :only => [:destroy, :restore]
before_action :require_allow_write_api, :only => [:create, :destroy, :restore]
before_action :require_public_data, :only => [:create]
before_action :check_api_writable, :only => [:create, :hide_comment, :unhide_comment]
before_action :check_api_writable, :only => [:create, :destroy, :restore]
before_action :check_api_readable, :except => [:create, :index]
before_action(:only => [:index]) { |c| c.check_database_readable(true) }
around_action :api_call_handle_error, :except => [:index]
@ -46,7 +46,7 @@ class ChangesetCommentsController < ApplicationController
##
# Sets visible flag on comment to false
def hide_comment
def destroy
# Check the arguments are sane
raise OSM::APIBadUserInput, "No id was given" unless params[:id]
@ -65,7 +65,7 @@ class ChangesetCommentsController < ApplicationController
##
# Sets visible flag on comment to true
def unhide_comment
def restore
# Check the arguments are sane
raise OSM::APIBadUserInput, "No id was given" unless params[:id]

View file

@ -17,8 +17,8 @@ OpenStreetMap::Application.routes.draw do
put "changeset/:id/close" => "changeset#close", :id => /\d+/
get "changesets" => "changeset#query"
post "changeset/:id/comment" => "changeset_comments#create", :as => :changeset_comment, :id => /\d+/
post "changeset/comment/:id/hide" => "changeset_comments#hide_comment", :as => :changeset_comment_hide, :id => /\d+/
post "changeset/comment/:id/unhide" => "changeset_comments#unhide_comment", :as => :changeset_comment_unhide, :id => /\d+/
post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :id => /\d+/
post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
put "node/create" => "node#create"
get "node/:id/ways" => "way#ways_for_node", :id => /\d+/

View file

@ -10,11 +10,11 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
)
assert_routing(
{ :path => "/api/0.6/changeset/comment/1/hide", :method => :post },
{ :controller => "changeset_comments", :action => "hide_comment", :id => "1" }
{ :controller => "changeset_comments", :action => "destroy", :id => "1" }
)
assert_routing(
{ :path => "/api/0.6/changeset/comment/1/unhide", :method => :post },
{ :controller => "changeset_comments", :action => "unhide_comment", :id => "1" }
{ :controller => "changeset_comments", :action => "restore", :id => "1" }
)
assert_routing(
{ :path => "/changeset/1/comments/feed", :method => :get },
@ -129,26 +129,26 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
##
# test hide comment fail
def test_hide_comment_fail
def test_destroy_comment_fail
# unauthorized
comment = create(:changeset_comment)
assert_equal true, comment.visible
post :hide_comment, :params => { :id => comment.id }
post :destroy, :params => { :id => comment.id }
assert_response :unauthorized
assert_equal true, comment.reload.visible
basic_authorization create(:user).email, "test"
# not a moderator
post :hide_comment, :params => { :id => comment.id }
post :destroy, :params => { :id => comment.id }
assert_response :forbidden
assert_equal true, comment.reload.visible
basic_authorization create(:moderator_user).email, "test"
# bad comment id
post :hide_comment, :params => { :id => 999111 }
post :destroy, :params => { :id => 999111 }
assert_response :not_found
assert_equal true, comment.reload.visible
end
@ -161,33 +161,33 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
basic_authorization create(:moderator_user).email, "test"
post :hide_comment, :params => { :id => comment.id }
post :destroy, :params => { :id => comment.id }
assert_response :success
assert_equal false, comment.reload.visible
end
##
# test unhide comment fail
def test_unhide_comment_fail
def test_restore_comment_fail
# unauthorized
comment = create(:changeset_comment, :visible => false)
assert_equal false, comment.visible
post :unhide_comment, :params => { :id => comment.id }
post :restore, :params => { :id => comment.id }
assert_response :unauthorized
assert_equal false, comment.reload.visible
basic_authorization create(:user).email, "test"
# not a moderator
post :unhide_comment, :params => { :id => comment.id }
post :restore, :params => { :id => comment.id }
assert_response :forbidden
assert_equal false, comment.reload.visible
basic_authorization create(:moderator_user).email, "test"
# bad comment id
post :unhide_comment, :params => { :id => 999111 }
post :restore, :params => { :id => 999111 }
assert_response :not_found
assert_equal false, comment.reload.visible
end
@ -200,7 +200,7 @@ class ChangesetCommentsControllerTest < ActionController::TestCase
basic_authorization create(:moderator_user).email, "test"
post :unhide_comment, :params => { :id => comment.id }
post :restore, :params => { :id => comment.id }
assert_response :success
assert_equal true, comment.reload.visible
end