summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
4b0d56f)
This preserves the API endpoints and HTTP methods, which could be changed in the next API version
class ChangesetCommentsController < ApplicationController
before_action :authorize_web, :only => [:index]
before_action :set_locale, :only => [:index]
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 :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]
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]
##
# Sets visible flag on comment to false
##
# Sets visible flag on comment to false
# Check the arguments are sane
raise OSM::APIBadUserInput, "No id was given" unless params[:id]
# Check the arguments are sane
raise OSM::APIBadUserInput, "No id was given" unless params[:id]
##
# Sets visible flag on comment to true
##
# Sets visible flag on comment to true
# Check the arguments are sane
raise OSM::APIBadUserInput, "No id was given" unless params[:id]
# Check the arguments are sane
raise OSM::APIBadUserInput, "No id was given" unless params[:id]
put "changeset/:id/close" => "changeset#close", :id => /\d+/
get "changesets" => "changeset#query"
post "changeset/:id/comment" => "changeset_comments#create", :as => :changeset_comment, :id => /\d+/
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+/
put "node/create" => "node#create"
get "node/:id/ways" => "way#ways_for_node", :id => /\d+/
)
assert_routing(
{ :path => "/api/0.6/changeset/comment/1/hide", :method => :post },
)
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 },
)
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 },
)
assert_routing(
{ :path => "/changeset/1/comments/feed", :method => :get },
##
# test hide comment fail
##
# test hide comment fail
- def test_hide_comment_fail
+ def test_destroy_comment_fail
# unauthorized
comment = create(:changeset_comment)
assert_equal true, comment.visible
# 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
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
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
assert_response :not_found
assert_equal true, comment.reload.visible
end
basic_authorization create(:moderator_user).email, "test"
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
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
# 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
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
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
assert_response :not_found
assert_equal false, comment.reload.visible
end
basic_authorization create(:moderator_user).email, "test"
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
assert_response :success
assert_equal true, comment.reload.visible
end