Make api old element show paths resourceful

This commit is contained in:
Anton Khorev 2025-02-08 20:29:15 +03:00
parent 29323be33b
commit f2ed3c1935
12 changed files with 151 additions and 117 deletions

View file

@ -3,7 +3,7 @@ module Api
private private
def lookup_old_element def lookup_old_element
@old_element = OldNode.find([params[:id], params[:version]]) @old_element = OldNode.find([params[:node_id], params[:version]])
end end
def lookup_old_element_versions def lookup_old_element_versions

View file

@ -3,7 +3,7 @@ module Api
private private
def lookup_old_element def lookup_old_element
@old_element = OldRelation.find([params[:id], params[:version]]) @old_element = OldRelation.find([params[:relation_id], params[:version]])
end end
def lookup_old_element_versions def lookup_old_element_versions

View file

@ -3,7 +3,7 @@ module Api
private private
def lookup_old_element def lookup_old_element
@old_element = OldWay.find([params[:id], params[:version]]) @old_element = OldWay.find([params[:way_id], params[:version]])
end end
def lookup_old_element_versions def lookup_old_element_versions

View file

@ -2,7 +2,7 @@
<%= link_to t("browse.view_details"), :controller => @type.pluralize, :action => :show %> <%= link_to t("browse.view_details"), :controller => @type.pluralize, :action => :show %>
<% if !@feature.redacted? %> <% if !@feature.redacted? %>
&middot; &middot;
<%= link_to t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => :show %> <%= link_to t("browse.download_xml"), send(:"api_#{@type}_version_path", *@feature.id) %>
<% elsif current_user&.moderator? %> <% elsif current_user&.moderator? %>
&middot; &middot;
<% if !params[:show_redactions] %> <% if !params[:show_redactions] %>

View file

@ -30,14 +30,11 @@ OpenStreetMap::Application.routes.draw do
post "changeset/comment/:id/hide" => "changeset_comments#destroy", :as => :changeset_comment_hide, :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+/ post "changeset/comment/:id/unhide" => "changeset_comments#restore", :as => :changeset_comment_unhide, :id => /\d+/
post "node/:id/:version/redact" => "old_nodes#redact", :as => :node_version_redact, :version => /\d+/, :id => /\d+/ post "node/:node_id/:version/redact" => "old_nodes#redact", :as => :node_version_redact, :version => /\d+/, :node_id => /\d+/
get "node/:id/:version" => "old_nodes#show", :as => :api_old_node, :id => /\d+/, :version => /\d+/
post "way/:id/:version/redact" => "old_ways#redact", :as => :way_version_redact, :version => /\d+/, :id => /\d+/ post "way/: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+/
post "relation/:id/:version/redact" => "old_relations#redact", :as => :relation_version_redact, :version => /\d+/, :id => /\d+/ post "relation/:relation_id/:version/redact" => "old_relations#redact", :as => :relation_version_redact, :version => /\d+/, :id => /\d+/
get "relation/:id/:version" => "old_relations#show", :as => :api_old_relation, :id => /\d+/, :version => /\d+/
end end
namespace :api, :path => "api/0.6" do namespace :api, :path => "api/0.6" do
@ -48,6 +45,7 @@ OpenStreetMap::Application.routes.draw do
resources :relations, :only => :index resources :relations, :only => :index
end end
resources :versions, :path => "history", :controller => :old_nodes, :only => :index resources :versions, :path => "history", :controller => :old_nodes, :only => :index
resources :versions, :path => "", :version => /\d+/, :param => :version, :controller => :old_nodes, :only => :show
end end
put "node/create" => "nodes#create", :as => nil put "node/create" => "nodes#create", :as => nil
@ -60,6 +58,7 @@ OpenStreetMap::Application.routes.draw do
resources :relations, :only => :index resources :relations, :only => :index
end end
resources :versions, :path => "history", :controller => :old_ways, :only => :index resources :versions, :path => "history", :controller => :old_ways, :only => :index
resources :versions, :path => "", :version => /\d+/, :param => :version, :controller => :old_ways, :only => :show
end end
put "way/create" => "ways#create", :as => nil put "way/create" => "ways#create", :as => nil
@ -72,6 +71,7 @@ OpenStreetMap::Application.routes.draw do
resources :relations, :only => :index resources :relations, :only => :index
end end
resources :versions, :path => "history", :controller => :old_relations, :only => :index resources :versions, :path => "history", :controller => :old_relations, :only => :index
resources :versions, :path => "", :version => /\d+/, :param => :version, :controller => :old_relations, :only => :show
end end
put "relation/create" => "relations#create", :as => nil put "relation/create" => "relations#create", :as => nil

View file

@ -15,15 +15,15 @@ module Api
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/node/1/2", :method => :get }, { :path => "/api/0.6/node/1/2", :method => :get },
{ :controller => "api/old_nodes", :action => "show", :id => "1", :version => "2" } { :controller => "api/old_nodes", :action => "show", :node_id => "1", :version => "2" }
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/node/1/2.json", :method => :get }, { :path => "/api/0.6/node/1/2.json", :method => :get },
{ :controller => "api/old_nodes", :action => "show", :id => "1", :version => "2", :format => "json" } { :controller => "api/old_nodes", :action => "show", :node_id => "1", :version => "2", :format => "json" }
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/node/1/2/redact", :method => :post }, { :path => "/api/0.6/node/1/2/redact", :method => :post },
{ :controller => "api/old_nodes", :action => "redact", :id => "1", :version => "2" } { :controller => "api/old_nodes", :action => "redact", :node_id => "1", :version => "2" }
) )
end end
@ -77,7 +77,7 @@ module Api
# #
## ##
# FIXME: Move this test to being an integration test since it spans multiple controllers # FIXME: Move this test to being an integration test since it spans multiple controllers
def test_version def test_show
private_user = create(:user, :data_public => false) private_user = create(:user, :data_public => false)
private_node = create(:node, :with_history, :version => 4, :lat => 0, :lon => 0, :changeset => create(:changeset, :user => private_user)) private_node = create(:node, :with_history, :version => 4, :lat => 0, :lon => 0, :changeset => create(:changeset, :user => private_user))
user = create(:user) user = create(:user)
@ -181,7 +181,7 @@ module Api
# check all the versions # check all the versions
versions.each_key do |key| versions.each_key do |key|
get api_old_node_path(nodeid, key.to_i) get api_node_version_path(nodeid, key.to_i)
assert_response :success, assert_response :success,
"couldn't get version #{key.to_i} of node #{nodeid}" "couldn't get version #{key.to_i} of node #{nodeid}"
@ -193,13 +193,30 @@ module Api
end end
end end
def test_not_found_version def test_show_not_found
check_not_found_id_version(70000, 312344) check_not_found_id_version(70000, 312344)
check_not_found_id_version(-1, -13) check_not_found_id_version(-1, -13)
check_not_found_id_version(create(:node).id, 24354) check_not_found_id_version(create(:node).id, 24354)
check_not_found_id_version(24356, create(:node).version) check_not_found_id_version(24356, create(:node).version)
end end
##
# test that redacted nodes aren't visible, regardless of
# authorisation except as moderator...
def test_show_redacted
node = create(:node, :with_history, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
get api_node_version_path(node_v1.node_id, node_v1.version)
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
# not even to a logged-in user
auth_header = bearer_authorization_header
get api_node_version_path(node_v1.node_id, node_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in."
end
## ##
# Test that getting the current version is identical to picking # Test that getting the current version is identical to picking
# that version with the version URI call. # that version with the version URI call.
@ -301,23 +318,6 @@ module Api
assert_response :success, "should be OK to redact old version as moderator with write_redactions scope." assert_response :success, "should be OK to redact old version as moderator with write_redactions scope."
end end
##
# test that redacted nodes aren't visible, regardless of
# authorisation except as moderator...
def test_version_redacted
node = create(:node, :with_history, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
get api_old_node_path(node_v1.node_id, node_v1.version)
assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
# not even to a logged-in user
auth_header = bearer_authorization_header
get api_old_node_path(node_v1.node_id, node_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted node shouldn't be visible via the version API, even when logged in."
end
## ##
# test the redaction of an old version of a node, while being # test the redaction of an old version of a node, while being
# authorised as a moderator. # authorised as a moderator.
@ -331,9 +331,9 @@ module Api
# check moderator can still see the redacted data, when passing # check moderator can still see the redacted data, when passing
# the appropriate flag # the appropriate flag
get api_old_node_path(node_v3.node_id, node_v3.version), :headers => auth_header get api_node_version_path(node_v3.node_id, node_v3.version), :headers => auth_header
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed." assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
get api_old_node_path(node_v3.node_id, node_v3.version, :show_redactions => "true"), :headers => auth_header get api_node_version_path(node_v3.node_id, node_v3.version, :show_redactions => "true"), :headers => auth_header
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed." assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history # and when accessed via history
@ -361,7 +361,7 @@ module Api
auth_header = bearer_authorization_header auth_header = bearer_authorization_header
# check can't see the redacted data # check can't see the redacted data
get api_old_node_path(node_v3.node_id, node_v3.version), :headers => auth_header get api_node_version_path(node_v3.node_id, node_v3.version), :headers => auth_header
assert_response :forbidden, "Redacted node shouldn't be visible via the version API." assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
# and when accessed via history # and when accessed via history
@ -414,7 +414,7 @@ module Api
# check moderator can now see the redacted data, when not # check moderator can now see the redacted data, when not
# passing the aspecial flag # passing the aspecial flag
get api_old_node_path(node_v1.node_id, node_v1.version), :headers => auth_header get api_node_version_path(node_v1.node_id, node_v1.version), :headers => auth_header
assert_response :success, "After unredaction, node should not be gone for moderator." assert_response :success, "After unredaction, node should not be gone for moderator."
# and when accessed via history # and when accessed via history
@ -426,7 +426,7 @@ module Api
auth_header = bearer_authorization_header auth_header = bearer_authorization_header
# check normal user can now see the redacted data # check normal user can now see the redacted data
get api_old_node_path(node_v1.node_id, node_v1.version), :headers => auth_header get api_node_version_path(node_v1.node_id, node_v1.version), :headers => auth_header
assert_response :success, "After unredaction, node should be visible to normal users." assert_response :success, "After unredaction, node should be visible to normal users."
# and when accessed via history # and when accessed via history
@ -445,7 +445,7 @@ module Api
end end
def do_redact_node(node, redaction, headers = {}) def do_redact_node(node, redaction, headers = {})
get api_old_node_path(node.node_id, node.version), :headers => headers get api_node_version_path(node.node_id, node.version), :headers => headers
assert_response :success, "should be able to get version #{node.version} of node #{node.node_id}." assert_response :success, "should be able to get version #{node.version} of node #{node.node_id}."
# now redact it # now redact it
@ -462,7 +462,7 @@ module Api
assert_not_nil current_node, "getting node #{node_id} returned nil" assert_not_nil current_node, "getting node #{node_id} returned nil"
# get the "old" version of the node from the old_node interface # get the "old" version of the node from the old_node interface
get api_old_node_path(node_id, current_node.version) get api_node_version_path(node_id, current_node.version)
assert_response :success, "cant get old node #{node_id}, v#{current_node.version}" assert_response :success, "cant get old node #{node_id}, v#{current_node.version}"
old_node = Node.from_xml(@response.body) old_node = Node.from_xml(@response.body)
@ -471,7 +471,7 @@ module Api
end end
def check_not_found_id_version(id, version) def check_not_found_id_version(id, version)
get api_old_node_path(id, version) get api_node_version_path(id, version)
assert_response :not_found assert_response :not_found
rescue ActionController::UrlGenerationError => e rescue ActionController::UrlGenerationError => e
assert_match(/No route matches/, e.to_s) assert_match(/No route matches/, e.to_s)

View file

@ -15,15 +15,15 @@ module Api
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/relation/1/2", :method => :get }, { :path => "/api/0.6/relation/1/2", :method => :get },
{ :controller => "api/old_relations", :action => "show", :id => "1", :version => "2" } { :controller => "api/old_relations", :action => "show", :relation_id => "1", :version => "2" }
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/relation/1/2.json", :method => :get }, { :path => "/api/0.6/relation/1/2.json", :method => :get },
{ :controller => "api/old_relations", :action => "show", :id => "1", :version => "2", :format => "json" } { :controller => "api/old_relations", :action => "show", :relation_id => "1", :version => "2", :format => "json" }
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/relation/1/2/redact", :method => :post }, { :path => "/api/0.6/relation/1/2/redact", :method => :post },
{ :controller => "api/old_relations", :action => "redact", :id => "1", :version => "2" } { :controller => "api/old_relations", :action => "redact", :relation_id => "1", :version => "2" }
) )
end end
@ -73,6 +73,57 @@ module Api
"redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history, even when logged in." "redacted relation #{relation_v1.relation_id} version #{relation_v1.version} shouldn't be present in the history, even when logged in."
end end
def test_show
relation = create(:relation, :with_history, :version => 2)
create(:old_relation_tag, :old_relation => relation.old_relations[0], :k => "k1", :v => "v1")
create(:old_relation_tag, :old_relation => relation.old_relations[1], :k => "k2", :v => "v2")
get api_relation_version_path(relation, 1)
assert_response :success
assert_dom "osm:root", 1 do
assert_dom "> relation", 1 do
assert_dom "> @id", relation.id.to_s
assert_dom "> @version", "1"
assert_dom "> tag", 1 do
assert_dom "> @k", "k1"
assert_dom "> @v", "v1"
end
end
end
get api_relation_version_path(relation, 2)
assert_response :success
assert_dom "osm:root", 1 do
assert_dom "> relation", 1 do
assert_dom "> @id", relation.id.to_s
assert_dom "> @version", "2"
assert_dom "> tag", 1 do
assert_dom "> @k", "k2"
assert_dom "> @v", "v2"
end
end
end
end
##
# test that redacted relations aren't visible, regardless of
# authorisation except as moderator...
def test_show_redacted
relation = create(:relation, :with_history, :version => 2)
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))
get api_relation_version_path(relation_v1.relation_id, relation_v1.version)
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
# not even to a logged-in user
auth_header = bearer_authorization_header
get api_relation_version_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in."
end
## ##
# test the redaction of an old version of a relation, while not being # test the redaction of an old version of a relation, while not being
# authorised. # authorised.
@ -134,23 +185,6 @@ module Api
assert_response :success, "should be OK to redact old version as moderator with write_redactions scope." assert_response :success, "should be OK to redact old version as moderator with write_redactions scope."
end end
##
# test that redacted relations aren't visible, regardless of
# authorisation except as moderator...
def test_version_redacted
relation = create(:relation, :with_history, :version => 2)
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))
get api_old_relation_path(relation_v1.relation_id, relation_v1.version)
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
# not even to a logged-in user
auth_header = bearer_authorization_header
get api_old_relation_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API, even when logged in."
end
## ##
# test the redaction of an old version of a relation, while being # test the redaction of an old version of a relation, while being
# authorised as a moderator. # authorised as a moderator.
@ -165,9 +199,9 @@ module Api
# check moderator can still see the redacted data, when passing # check moderator can still see the redacted data, when passing
# the appropriate flag # the appropriate flag
get api_old_relation_path(relation_v3.relation_id, relation_v3.version), :headers => auth_header get api_relation_version_path(relation_v3.relation_id, relation_v3.version), :headers => auth_header
assert_response :forbidden, "After redaction, relation should be gone for moderator, when flag not passed." assert_response :forbidden, "After redaction, relation should be gone for moderator, when flag not passed."
get api_old_relation_path(relation_v3.relation_id, relation_v3.version, :show_redactions => "true"), :headers => auth_header get api_relation_version_path(relation_v3.relation_id, relation_v3.version, :show_redactions => "true"), :headers => auth_header
assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed." assert_response :success, "After redaction, relation should not be gone for moderator, when flag passed."
# and when accessed via history # and when accessed via history
@ -196,7 +230,7 @@ module Api
auth_header = bearer_authorization_header auth_header = bearer_authorization_header
# check can't see the redacted data # check can't see the redacted data
get api_old_relation_path(relation_v3.relation_id, relation_v3.version), :headers => auth_header get api_relation_version_path(relation_v3.relation_id, relation_v3.version), :headers => auth_header
assert_response :forbidden, "Redacted relation shouldn't be visible via the version API." assert_response :forbidden, "Redacted relation shouldn't be visible via the version API."
# and when accessed via history # and when accessed via history
@ -247,7 +281,7 @@ module Api
# check moderator can still see the redacted data, without passing # check moderator can still see the redacted data, without passing
# the appropriate flag # the appropriate flag
get api_old_relation_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header get api_relation_version_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
assert_response :success, "After unredaction, relation should not be gone for moderator." assert_response :success, "After unredaction, relation should not be gone for moderator."
# and when accessed via history # and when accessed via history
@ -259,7 +293,7 @@ module Api
auth_header = bearer_authorization_header auth_header = bearer_authorization_header
# check normal user can now see the redacted data # check normal user can now see the redacted data
get api_old_relation_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header get api_relation_version_path(relation_v1.relation_id, relation_v1.version), :headers => auth_header
assert_response :success, "After redaction, node should not be gone for normal user." assert_response :success, "After redaction, node should not be gone for normal user."
# and when accessed via history # and when accessed via history
@ -321,7 +355,7 @@ module Api
end end
def do_redact_relation(relation, redaction, headers = {}) def do_redact_relation(relation, redaction, headers = {})
get api_old_relation_path(relation.relation_id, relation.version) get api_relation_version_path(relation.relation_id, relation.version)
assert_response :success, "should be able to get version #{relation.version} of relation #{relation.relation_id}." assert_response :success, "should be able to get version #{relation.version} of relation #{relation.relation_id}."
# now redact it # now redact it

View file

@ -15,15 +15,15 @@ module Api
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/way/1/2", :method => :get }, { :path => "/api/0.6/way/1/2", :method => :get },
{ :controller => "api/old_ways", :action => "show", :id => "1", :version => "2" } { :controller => "api/old_ways", :action => "show", :way_id => "1", :version => "2" }
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/way/1/2.json", :method => :get }, { :path => "/api/0.6/way/1/2.json", :method => :get },
{ :controller => "api/old_ways", :action => "show", :id => "1", :version => "2", :format => "json" } { :controller => "api/old_ways", :action => "show", :way_id => "1", :version => "2", :format => "json" }
) )
assert_routing( assert_routing(
{ :path => "/api/0.6/way/1/2/redact", :method => :post }, { :path => "/api/0.6/way/1/2/redact", :method => :post },
{ :controller => "api/old_ways", :action => "redact", :id => "1", :version => "2" } { :controller => "api/old_ways", :action => "redact", :way_id => "1", :version => "2" }
) )
end end
@ -82,7 +82,7 @@ module Api
## ##
# check that we can retrieve versions of a way # check that we can retrieve versions of a way
def test_version def test_show
way = create(:way, :with_history) way = create(:way, :with_history)
used_way = create(:way, :with_history) used_way = create(:way, :with_history)
create(:relation_member, :member => used_way) create(:relation_member, :member => used_way)
@ -100,6 +100,23 @@ module Api
check_current_version(way_with_versions.id) check_current_version(way_with_versions.id)
end end
##
# test that redacted ways aren't visible, regardless of
# authorisation except as moderator...
def test_show_redacted
way = create(:way, :with_history, :version => 2)
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))
get api_way_version_path(way_v1.way_id, way_v1.version)
assert_response :forbidden, "Redacted way shouldn't be visible via the version API."
# not even to a logged-in user
auth_header = bearer_authorization_header
get api_way_version_path(way_v1.way_id, way_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted way shouldn't be visible via the version API, even when logged in."
end
## ##
# check that returned history is the same as getting all # check that returned history is the same as getting all
# versions of a way from the api. # versions of a way from the api.
@ -173,23 +190,6 @@ module Api
assert_response :success, "should be OK to redact old version as moderator with write_redactions scope." assert_response :success, "should be OK to redact old version as moderator with write_redactions scope."
end end
##
# test that redacted ways aren't visible, regardless of
# authorisation except as moderator...
def test_version_redacted
way = create(:way, :with_history, :version => 2)
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))
get api_old_way_path(way_v1.way_id, way_v1.version)
assert_response :forbidden, "Redacted way shouldn't be visible via the version API."
# not even to a logged-in user
auth_header = bearer_authorization_header
get api_old_way_path(way_v1.way_id, way_v1.version), :headers => auth_header
assert_response :forbidden, "Redacted way shouldn't be visible via the version API, even when logged in."
end
## ##
# test the redaction of an old version of a way, while being # test the redaction of an old version of a way, while being
# authorised as a moderator. # authorised as a moderator.
@ -203,9 +203,9 @@ module Api
# check moderator can still see the redacted data, when passing # check moderator can still see the redacted data, when passing
# the appropriate flag # the appropriate flag
get api_old_way_path(way_v3.way_id, way_v3.version), :headers => auth_header get api_way_version_path(way_v3.way_id, way_v3.version), :headers => auth_header
assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed." assert_response :forbidden, "After redaction, node should be gone for moderator, when flag not passed."
get api_old_way_path(way_v3.way_id, way_v3.version, :show_redactions => "true"), :headers => auth_header get api_way_version_path(way_v3.way_id, way_v3.version, :show_redactions => "true"), :headers => auth_header
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed." assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history # and when accessed via history
@ -233,7 +233,7 @@ module Api
auth_header = bearer_authorization_header auth_header = bearer_authorization_header
# check can't see the redacted data # check can't see the redacted data
get api_old_way_path(way_v3.way_id, way_v3.version), :headers => auth_header get api_way_version_path(way_v3.way_id, way_v3.version), :headers => auth_header
assert_response :forbidden, "Redacted node shouldn't be visible via the version API." assert_response :forbidden, "Redacted node shouldn't be visible via the version API."
# and when accessed via history # and when accessed via history
@ -285,7 +285,7 @@ module Api
# check moderator can still see the unredacted data, without passing # check moderator can still see the unredacted data, without passing
# the appropriate flag # the appropriate flag
get api_old_way_path(way_v1.way_id, way_v1.version), :headers => auth_header get api_way_version_path(way_v1.way_id, way_v1.version), :headers => auth_header
assert_response :success, "After unredaction, node should not be gone for moderator." assert_response :success, "After unredaction, node should not be gone for moderator."
# and when accessed via history # and when accessed via history
@ -297,7 +297,7 @@ module Api
auth_header = bearer_authorization_header auth_header = bearer_authorization_header
# check normal user can now see the unredacted data # check normal user can now see the unredacted data
get api_old_way_path(way_v1.way_id, way_v1.version), :headers => auth_header get api_way_version_path(way_v1.way_id, way_v1.version), :headers => auth_header
assert_response :success, "After redaction, node should not be gone for moderator, when flag passed." assert_response :success, "After redaction, node should not be gone for moderator, when flag passed."
# and when accessed via history # and when accessed via history
@ -322,7 +322,7 @@ module Api
assert_not_nil current_way, "getting way #{way_id} returned nil" assert_not_nil current_way, "getting way #{way_id} returned nil"
# get the "old" version of the way from the version method # get the "old" version of the way from the version method
get api_old_way_path(way_id, current_way.version) get api_way_version_path(way_id, current_way.version)
assert_response :success, "can't get old way #{way_id}, v#{current_way.version}" assert_response :success, "can't get old way #{way_id}, v#{current_way.version}"
old_way = Way.from_xml(@response.body) old_way = Way.from_xml(@response.body)
@ -343,7 +343,7 @@ module Api
history_way = Way.from_xml_node(way_doc) history_way = Way.from_xml_node(way_doc)
assert_not_nil history_way, "parsing way #{way_id} version failed" assert_not_nil history_way, "parsing way #{way_id} version failed"
get api_old_way_path(way_id, history_way.version) get api_way_version_path(way_id, history_way.version)
assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}" assert_response :success, "couldn't get way #{way_id}, v#{history_way.version}"
version_way = Way.from_xml(@response.body) version_way = Way.from_xml(@response.body)
assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}" assert_not_nil version_way, "failed to parse #{way_id}, v#{history_way.version}"
@ -359,7 +359,7 @@ module Api
end end
def do_redact_way(way, redaction, headers = {}) def do_redact_way(way, redaction, headers = {})
get api_old_way_path(way.way_id, way.version) get api_way_version_path(way.way_id, way.version)
assert_response :success, "should be able to get version #{way.version} of way #{way.way_id}." assert_response :success, "should be able to get version #{way.version} of way #{way.way_id}."
# now redact it # now redact it

View file

@ -782,7 +782,7 @@ module Api
# check the ordering in the history tables: # check the ordering in the history tables:
with_controller(OldRelationsController.new) do with_controller(OldRelationsController.new) do
get api_old_relation_path(relation_id, 2) get api_relation_version_path(relation_id, 2)
assert_response :success, "can't read back version 2 of the relation #{relation_id}" assert_response :success, "can't read back version 2 of the relation #{relation_id}"
check_ordering(doc, @response.body) check_ordering(doc, @response.body)
end end
@ -862,7 +862,7 @@ module Api
# check the ordering in the history tables: # check the ordering in the history tables:
with_controller(OldRelationsController.new) do with_controller(OldRelationsController.new) do
get api_old_relation_path(relation_id, 1) get api_relation_version_path(relation_id, 1)
assert_response :success, "can't read back version 1 of the relation: #{@response.body}" assert_response :success, "can't read back version 1 of the relation: #{@response.body}"
check_ordering(doc, @response.body) check_ordering(doc, @response.body)
end end
@ -1084,7 +1084,7 @@ module Api
get api_relation_path(id) get api_relation_path(id)
else else
with_controller(OldRelationsController.new) do with_controller(OldRelationsController.new) do
get api_old_relation_path(id, ver) get api_relation_version_path(id, ver)
end end
end end
assert_response :success assert_response :success

View file

@ -114,7 +114,7 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_node_path node, 1}']", :count => 0 assert_select "a[href='#{old_node_path node, 1}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_node_path node, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 1
assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
@ -129,7 +129,7 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_node_path node, 1}']", :count => 0 assert_select "a[href='#{old_node_path node, 1}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_node_path node, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 1
assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1 assert_select ".secondary-actions a[href='#{old_node_path node, 2}']", :count => 1
@ -141,7 +141,7 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_node_path node, 2}']", :count => 0 assert_select "a[href='#{old_node_path node, 2}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_node_path node, 2}']", :count => 1 assert_select ".secondary-actions a[href='#{api_node_version_path node, 2}']", :count => 1
assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_history_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
@ -157,7 +157,7 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_node_path node, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0
end end
test "show unrevealed redacted versions to regular users" do test "show unrevealed redacted versions to regular users" do
@ -171,7 +171,7 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_node_path node, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0
end end
test "show unrevealed redacted versions to moderators" do test "show unrevealed redacted versions to moderators" do
@ -185,7 +185,7 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1 assert_select ".secondary-actions a[href='#{node_path node}']", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 1 assert_select ".secondary-actions a[href='#{old_node_path node, 1, :params => { :show_redactions => true }}']", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_node_path node, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_node_version_path node, 1}']", :count => 0
end end
test "don't reveal redacted versions to anonymous users" do test "don't reveal redacted versions to anonymous users" do

View file

@ -64,7 +64,7 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0 assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 1
assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
@ -79,7 +79,7 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0 assert_select "a[href='#{old_relation_path relation, 1}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 1
assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1 assert_select ".secondary-actions a[href='#{old_relation_path relation, 2}']", :count => 1
@ -91,7 +91,7 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_relation_path relation, 2}']", :count => 0 assert_select "a[href='#{old_relation_path relation, 2}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 2}']", :count => 1 assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 2}']", :count => 1
assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_history_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
@ -116,7 +116,7 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 0
end end
test "show unrevealed redacted versions to regular users" do test "show unrevealed redacted versions to regular users" do
@ -130,7 +130,7 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 0
end end
test "show unrevealed redacted versions to moderators" do test "show unrevealed redacted versions to moderators" do
@ -144,7 +144,7 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1 assert_select ".secondary-actions a[href='#{relation_path relation}']", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 1 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1, :params => { :show_redactions => true }}']", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_relation_path relation, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_relation_version_path relation, 1}']", :count => 0
end end
test "don't reveal redacted versions to anonymous users" do test "don't reveal redacted versions to anonymous users" do

View file

@ -64,7 +64,7 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_way_path way, 1}']", :count => 0 assert_select "a[href='#{old_way_path way, 1}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 1
assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
@ -79,7 +79,7 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_way_path way, 1}']", :count => 0 assert_select "a[href='#{old_way_path way, 1}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 1
assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1 assert_select ".secondary-actions a[href='#{old_way_path way, 2}']", :count => 1
@ -91,7 +91,7 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_select "h4", /^Version/ do assert_select "h4", /^Version/ do
assert_select "a[href='#{old_way_path way, 2}']", :count => 0 assert_select "a[href='#{old_way_path way, 2}']", :count => 0
end end
assert_select ".secondary-actions a[href='#{api_old_way_path way, 2}']", :count => 1 assert_select ".secondary-actions a[href='#{api_way_version_path way, 2}']", :count => 1
assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_history_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
@ -121,7 +121,7 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 0
end end
test "show unrevealed redacted versions to regular users" do test "show unrevealed redacted versions to regular users" do
@ -135,7 +135,7 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 0
assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 0
end end
test "show unrevealed redacted versions to moderators" do test "show unrevealed redacted versions to moderators" do
@ -149,7 +149,7 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1 assert_select ".secondary-actions a[href='#{way_path way}']", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 1 assert_select ".secondary-actions a[href='#{old_way_path way, 1, :params => { :show_redactions => true }}']", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 0
assert_select ".secondary-actions a[href='#{api_old_way_path way, 1}']", :count => 0 assert_select ".secondary-actions a[href='#{api_way_version_path way, 1}']", :count => 0
end end
test "don't reveal redacted versions to anonymous users" do test "don't reveal redacted versions to anonymous users" do