Merge remote-tracking branch 'upstream/pull/4324'

This commit is contained in:
Tom Hughes 2024-03-01 19:23:51 +00:00
commit 664d02982c
19 changed files with 417 additions and 97 deletions

View file

@ -166,6 +166,21 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
assert_select ".browse-section.browse-node .longitude", 0
end
def test_redacted_node_unredacted_history
session_for(create(:moderator_user))
node = create(:node, :with_history, :deleted, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
get node_history_path(:id => node, :params => { :show_redactions => true })
assert_response :success
assert_template "browse/history"
assert_select ".browse-section", 2
assert_select ".browse-section.browse-redacted", 0
assert_select ".browse-section.browse-node", 2
end
def test_redacted_way_history
way = create(:way, :with_history, :version => 4)
way_v1 = way.old_ways.find_by(:version => 1)
@ -184,6 +199,23 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
assert_select ".browse-section.browse-way", 2
end
def test_redacted_way_unredacted_history
session_for(create(:moderator_user))
way = create(:way, :with_history, :version => 4)
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))
way_v3 = way.old_ways.find_by(:version => 3)
way_v3.redact!(create(:redaction))
get way_history_path(:id => way, :params => { :show_redactions => true })
assert_response :success
assert_template "browse/history"
assert_select ".browse-section", 4
assert_select ".browse-section.browse-redacted", 0
assert_select ".browse-section.browse-way", 4
end
def test_redacted_relation_history
relation = create(:relation, :with_history, :version => 4)
relation_v1 = relation.old_relations.find_by(:version => 1)
@ -202,9 +234,107 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
assert_select ".browse-section.browse-relation", 2
end
def test_redacted_relation_unredacted_history
session_for(create(:moderator_user))
relation = create(:relation, :with_history, :version => 4)
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))
relation_v3 = relation.old_relations.find_by(:version => 3)
relation_v3.redact!(create(:redaction))
get relation_history_path(:id => relation, :params => { :show_redactions => true })
assert_response :success
assert_template "browse/history"
assert_select ".browse-section", 4
assert_select ".browse-section.browse-redacted", 0
assert_select ".browse-section.browse-relation", 4
end
def test_query
get query_path
assert_response :success
assert_template "browse/query"
end
def test_anonymous_user_feature_page_secondary_actions
node = create(:node, :with_history)
get node_path(:id => node)
assert_response :success
assert_select ".secondary-actions a", :text => "View Details", :count => 0
assert_select ".secondary-actions a", :text => "View History", :count => 1
assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
end
def test_regular_user_feature_page_secondary_actions
session_for(create(:user))
node = create(:node, :with_history)
get node_path(:id => node)
assert_response :success
assert_select ".secondary-actions a", :text => "View Details", :count => 0
assert_select ".secondary-actions a", :text => "View History", :count => 1
assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
end
def test_moderator_user_feature_page_secondary_actions
session_for(create(:moderator_user))
node = create(:node, :with_history)
get node_path(:id => node)
assert_response :success
assert_select ".secondary-actions a", :text => "View Details", :count => 0
assert_select ".secondary-actions a", :text => "View History", :count => 1
assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
end
def test_anonymous_user_history_page_secondary_actions
node = create(:node, :with_history)
get node_history_path(:id => node)
assert_response :success
assert_select ".secondary-actions a", :text => "View Details", :count => 1
assert_select ".secondary-actions a", :text => "View History", :count => 0
assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
end
def test_regular_user_history_page_secondary_actions
session_for(create(:user))
node = create(:node, :with_history)
get node_history_path(:id => node)
assert_response :success
assert_select ".secondary-actions a", :text => "View Details", :count => 1
assert_select ".secondary-actions a", :text => "View History", :count => 0
assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
end
def test_moderator_user_history_page_secondary_actions
session_for(create(:moderator_user))
node = create(:node, :with_history)
get node_history_path(:id => node)
assert_response :success
assert_select ".secondary-actions a", :text => "View Details", :count => 1
assert_select ".secondary-actions a", :text => "View History", :count => 0
assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 1
end
def test_anonymous_user_unredacted_history_page_secondary_actions
node = create(:node, :with_history)
get node_history_path(:id => node, :params => { :show_redactions => true })
assert_response :redirect
end
def test_regular_user_unredacted_history_page_secondary_actions
session_for(create(:user))
node = create(:node, :with_history)
get node_history_path(:id => node, :params => { :show_redactions => true })
assert_response :redirect
end
def test_moderator_user_unredacted_history_page_secondary_actions
session_for(create(:moderator_user))
node = create(:node, :with_history)
get node_history_path(:id => node, :params => { :show_redactions => true })
assert_response :success
assert_select ".secondary-actions a", :text => "View Details", :count => 1
assert_select ".secondary-actions a", :text => "View History", :count => 1
assert_select ".secondary-actions a", :text => "View Unredacted History", :count => 0
end
end

View file

@ -19,6 +19,7 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
end
assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :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='#{node_history_path node}']", :count => 1
end
@ -49,19 +50,69 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
end
def test_redacted
node = create(:node, :with_history, :deleted, :version => 2)
node_v1 = node.old_nodes.find_by(:version => 1)
node_v1.redact!(create(:redaction))
test "show unrevealed redacted versions to anonymous users" do
node = create_redacted_node
get old_node_path(node, 1)
assert_response :success
assert_template "old_nodes/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
end
test "show unrevealed redacted versions to regular users" do
session_for(create(:user))
node = create_redacted_node
get old_node_path(node, 1)
assert_response :success
assert_template "old_nodes/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
end
test "show unrevealed redacted versions to moderators" do
session_for(create(:moderator_user))
node = create_redacted_node
get old_node_path(node, 1)
assert_response :success
assert_template "old_nodes/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{node_version_path node, 1}']", :count => 0
end
test "don't reveal redacted versions to anonymous users" do
node = create_redacted_node
get old_node_path(node, 1, :params => { :show_redactions => true })
assert_response :redirect
end
test "don't reveal redacted versions to regular users" do
session_for(create(:user))
node = create_redacted_node
get old_node_path(node, 1, :params => { :show_redactions => true })
assert_response :redirect
end
test "reveal redacted versions to moderators" do
session_for(create(:moderator_user))
node = create_redacted_node
get old_node_path(node, 1, :params => { :show_redactions => true })
assert_response :success
assert_select "td", :text => "TOP SECRET", :count => 1
assert_select ".secondary-actions a[href='#{old_node_path node, 1}']", :count => 1
end
def test_not_found
get old_node_path(0, 0)
assert_response :not_found
@ -69,4 +120,14 @@ class OldNodesControllerTest < ActionDispatch::IntegrationTest
assert_template :layout => "map"
assert_select "#sidebar_content", /node #0 version 0 could not be found/
end
private
def create_redacted_node
create(:node, :with_history, :version => 2) do |node|
node_v1 = node.old_nodes.find_by(:version => 1)
create(:old_node_tag, :old_node => node_v1, :k => "name", :v => "TOP SECRET")
node_v1.redact!(create(:redaction))
end
end
end

View file

@ -19,6 +19,7 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
end
assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :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='#{relation_history_path relation}']", :count => 1
end
@ -58,19 +59,69 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_template :layout => "map"
end
def test_redacted
relation = create(:relation, :with_history, :deleted, :version => 2)
relation_v1 = relation.old_relations.find_by(:version => 1)
relation_v1.redact!(create(:redaction))
test "show unrevealed redacted versions to anonymous users" do
relation = create_redacted_relation
get old_relation_path(relation, 1)
assert_response :success
assert_template "old_relations/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :count => 0
end
test "show unrevealed redacted versions to regular users" do
session_for(create(:user))
relation = create_redacted_relation
get old_relation_path(relation, 1)
assert_response :success
assert_template "old_relations/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :count => 0
end
test "show unrevealed redacted versions to moderators" do
session_for(create(:moderator_user))
relation = create_redacted_relation
get old_relation_path(relation, 1)
assert_response :success
assert_template "old_relations/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{relation_version_path relation, 1}']", :count => 0
end
test "don't reveal redacted versions to anonymous users" do
relation = create_redacted_relation
get old_relation_path(relation, 1, :params => { :show_redactions => true })
assert_response :redirect
end
test "don't reveal redacted versions to regular users" do
session_for(create(:user))
relation = create_redacted_relation
get old_relation_path(relation, 1, :params => { :show_redactions => true })
assert_response :redirect
end
test "reveal redacted versions to moderators" do
session_for(create(:moderator_user))
relation = create_redacted_relation
get old_relation_path(relation, 1, :params => { :show_redactions => true })
assert_response :success
assert_select "td", :text => "TOP SECRET", :count => 1
assert_select ".secondary-actions a[href='#{old_relation_path relation, 1}']", :count => 1
end
def test_not_found
get old_relation_path(0, 0)
assert_response :not_found
@ -78,4 +129,14 @@ class OldRelationsControllerTest < ActionDispatch::IntegrationTest
assert_template :layout => "map"
assert_select "#sidebar_content", /relation #0 version 0 could not be found/
end
private
def create_redacted_relation
create(:relation, :with_history, :version => 2) do |relation|
relation_v1 = relation.old_relations.find_by(:version => 1)
create(:old_relation_tag, :old_relation => relation_v1, :k => "name", :v => "TOP SECRET")
relation_v1.redact!(create(:redaction))
end
end
end

View file

@ -19,6 +19,7 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
end
assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :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='#{way_history_path way}']", :count => 1
end
@ -63,19 +64,69 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_template :layout => "map"
end
def test_redacted
way = create(:way, :with_history, :deleted, :version => 2)
way_v1 = way.old_ways.find_by(:version => 1)
way_v1.redact!(create(:redaction))
test "show unrevealed redacted versions to anonymous users" do
way = create_redacted_way
get old_way_path(way, 1)
assert_response :success
assert_template "old_ways/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 0
end
test "show unrevealed redacted versions to regular users" do
session_for(create(:user))
way = create_redacted_way
get old_way_path(way, 1)
assert_response :success
assert_template "old_ways/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 0
end
test "show unrevealed redacted versions to moderators" do
session_for(create(:moderator_user))
way = create_redacted_way
get old_way_path(way, 1)
assert_response :success
assert_template "old_ways/show"
assert_template :layout => "map"
assert_select "td", :text => "TOP SECRET", :count => 0
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}']", :count => 0
assert_select ".secondary-actions a[href='#{way_version_path way, 1}']", :count => 0
end
test "don't reveal redacted versions to anonymous users" do
way = create_redacted_way
get old_way_path(way, 1, :params => { :show_redactions => true })
assert_response :redirect
end
test "don't reveal redacted versions to regular users" do
session_for(create(:user))
way = create_redacted_way
get old_way_path(way, 1, :params => { :show_redactions => true })
assert_response :redirect
end
test "reveal redacted versions to moderators" do
session_for(create(:moderator_user))
way = create_redacted_way
get old_way_path(way, 1, :params => { :show_redactions => true })
assert_response :success
assert_select "td", :text => "TOP SECRET", :count => 1
assert_select ".secondary-actions a[href='#{old_way_path way, 1}']", :count => 1
end
def test_not_found
get old_way_path(0, 0)
assert_response :not_found
@ -83,4 +134,14 @@ class OldWaysControllerTest < ActionDispatch::IntegrationTest
assert_template :layout => "map"
assert_select "#sidebar_content", /way #0 version 0 could not be found/
end
private
def create_redacted_way
create(:way, :with_history, :version => 2) do |way|
way_v1 = way.old_ways.find_by(:version => 1)
create(:old_way_tag, :old_way => way_v1, :k => "name", :v => "TOP SECRET")
way_v1.redact!(create(:redaction))
end
end
end