]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/4324'
authorTom Hughes <tom@compton.nu>
Fri, 1 Mar 2024 19:23:51 +0000 (19:23 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 1 Mar 2024 19:23:51 +0000 (19:23 +0000)
19 files changed:
app/controllers/browse_controller.rb
app/controllers/old_nodes_controller.rb
app/controllers/old_relations_controller.rb
app/controllers/old_ways_controller.rb
app/views/browse/_common_details.html.erb
app/views/browse/_node.html.erb
app/views/browse/_relation.html.erb
app/views/browse/_version_actions.erb [new file with mode: 0644]
app/views/browse/_way.html.erb
app/views/browse/feature.html.erb
app/views/browse/history.html.erb
app/views/old_nodes/show.html.erb
app/views/old_relations/show.html.erb
app/views/old_ways/show.html.erb
config/locales/en.yml
test/controllers/browse_controller_test.rb
test/controllers/old_nodes_controller_test.rb
test/controllers/old_relations_controller_test.rb
test/controllers/old_ways_controller_test.rb

index 82cbe6f9808e68083c44d71c9abd24fdc4e4952c..db291f6eb89a8fc5900cd8c4da953f987473c55e 100644 (file)
@@ -6,6 +6,7 @@ class BrowseController < ApplicationController
   before_action -> { check_database_readable(:need_api => true) }
   before_action :require_oauth
   before_action :update_totp, :only => [:query]
+  before_action :require_moderator_for_unredacted_history, :only => [:relation_history, :way_history, :node_history]
   around_action :web_timeout
   authorize_resource :class => false
 
@@ -58,4 +59,10 @@ class BrowseController < ApplicationController
   end
 
   def query; end
+
+  private
+
+  def require_moderator_for_unredacted_history
+    deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
+  end
 end
index a5b9cf563c5b063cd5d997749a793ce612b48489..9ef2ef881671550281858e5d8d967760646eb456 100644 (file)
@@ -8,6 +8,7 @@ class OldNodesController < ApplicationController
 
   authorize_resource
 
+  before_action :require_moderator_for_unredacted_history
   around_action :web_timeout
 
   def show
@@ -16,4 +17,10 @@ class OldNodesController < ApplicationController
   rescue ActiveRecord::RecordNotFound
     render :action => "not_found", :status => :not_found
   end
+
+  private
+
+  def require_moderator_for_unredacted_history
+    deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
+  end
 end
index 9dda82021e21c46afe81db153d93fe51478ee201..b9e151a4fd8b9cc702bf753bc700efcb60528afc 100644 (file)
@@ -8,6 +8,7 @@ class OldRelationsController < ApplicationController
 
   authorize_resource
 
+  before_action :require_moderator_for_unredacted_history
   around_action :web_timeout
 
   def show
@@ -16,4 +17,10 @@ class OldRelationsController < ApplicationController
   rescue ActiveRecord::RecordNotFound
     render :action => "not_found", :status => :not_found
   end
+
+  private
+
+  def require_moderator_for_unredacted_history
+    deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
+  end
 end
index d18121e6fe8652994729e14aa5808b6ebd1358c8..dd3c3279fd41fa54928bbe13362da0e7468e2055 100644 (file)
@@ -8,6 +8,7 @@ class OldWaysController < ApplicationController
 
   authorize_resource
 
+  before_action :require_moderator_for_unredacted_history
   around_action :web_timeout
 
   def show
@@ -16,4 +17,10 @@ class OldWaysController < ApplicationController
   rescue ActiveRecord::RecordNotFound
     render :action => "not_found", :status => :not_found
   end
+
+  private
+
+  def require_moderator_for_unredacted_history
+    deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
+  end
 end
index 7d3f8e829c672d3bc0c05ebc1acaf178cfda4e73..195332b099d5ff98c0a4c600a614030033c94067 100644 (file)
@@ -1,5 +1,9 @@
 <h4>
-  <%= t "browse.version" %>
+  <%= if common_details.redacted?
+        t "browse.redacted_version"
+      else
+        t "browse.version"
+      end %>
   #<%= link_to_unless_current common_details.version, :controller => "old_#{@type.pluralize}", :action => :show, :version => common_details.version %>
 </h4>
 
index 6c6c1fdf32a32b12bd09ebfade54e2524b8e708e..e395a4283832c99054de1f2829f37ed025795218 100644 (file)
@@ -1,4 +1,4 @@
-<% if node.redacted? %>
+<% if node.redacted? && !params[:show_redactions] %>
   <div class="browse-section browse-redacted">
     <%= t "browse.redacted.message_html",
           :type => t("browse.redacted.type.node"),
@@ -7,7 +7,7 @@
                                        :id => node.redaction.id), node.redaction) %>
   </div>
 <% else %>
-  <div class="browse-section browse-node">
+  <%= tag.div :class => ["browse-section", "browse-node", { "text-muted" => node.redacted? }] do %>
     <%= render :partial => "browse/common_details", :object => node %>
 
     <% unless node.ways.empty? and node.containing_relation_members.empty? %>
@@ -31,5 +31,5 @@
         </details>
       <% end %>
     <% end %>
-  </div>
+  <% end %>
 <% end %>
index c513ea6d1eba6fd666dfea5c017e268341ec4513..922e642cc76b18f2942f1b1eb9387256b35baf3f 100644 (file)
@@ -1,4 +1,4 @@
-<% if relation.redacted? %>
+<% if relation.redacted? && !params[:show_redactions] %>
   <div class="browse-section browse-redacted">
     <%= t "browse.redacted.message_html",
           :type => t("browse.redacted.type.relation"),
@@ -7,7 +7,7 @@
                                        :id => relation.redaction.id), relation.redaction) %>
   </div>
 <% else %>
-  <div class="browse-section browse-relation">
+  <%= tag.div :class => ["browse-section", "browse-relation", { "text-muted" => relation.redacted? }] do %>
     <%= render :partial => "browse/common_details", :object => relation %>
 
     <% unless relation.containing_relation_members.empty? %>
@@ -29,5 +29,5 @@
         </ul>
       </details>
     <% end %>
-  </div>
+  <% end %>
 <% end %>
diff --git a/app/views/browse/_version_actions.erb b/app/views/browse/_version_actions.erb
new file mode 100644 (file)
index 0000000..46bfd0d
--- /dev/null
@@ -0,0 +1,32 @@
+<div class='secondary-actions'>
+  <%= link_to t("browse.view_details"), :controller => :browse, :action => @type %>
+  <% if !@feature.redacted? %>
+    &middot;
+    <%= link_to t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => :version %>
+  <% elsif current_user&.moderator? %>
+    &middot;
+    <% if !params[:show_redactions] %>
+      <%= link_to t("browse.view_redacted_data"), :params => { :show_redactions => true } %>
+    <% else %>
+      <%= link_to t("browse.view_redaction_message") %>
+    <% end %>
+  <% end %>
+</div>
+
+<div class='secondary-actions'>
+  <% if @feature.version > 1 %>
+    <%= link_to({ :version => @feature.version - 1 }, { :class => "icon-link" }) do %>
+      <%= previous_page_svg_tag :height => 11 %>
+      <%= "#{t('browse.version')} ##{@feature.version - 1}" %>
+    <% end %>
+    &middot;
+  <% end %>
+  <%= link_to t("browse.view_history"), :controller => :browse, :action => "#{@type}_history" %>
+  <% unless @feature.latest_version? %>
+    &middot;
+    <%= link_to({ :version => @feature.version + 1 }, { :class => "icon-link" }) do %>
+      <%= "#{t('browse.version')} ##{@feature.version + 1}" %>
+      <%= next_page_svg_tag :height => 11 %>
+    <% end %>
+  <% end %>
+</div>
index 7197298aca6a5501acd0644d429b020eab4f8169..d93321a0fab98f3b14a93cbf23d3f9267d7076fa 100644 (file)
@@ -1,4 +1,4 @@
-<% if way.redacted? %>
+<% if way.redacted? && !params[:show_redactions] %>
   <div class="browse-section browse-redacted">
     <%= t "browse.redacted.message_html",
           :type => t("browse.redacted.type.way"),
@@ -7,7 +7,7 @@
                                        :id => way.redaction.id), way.redaction) %>
   </div>
 <% else %>
-  <div class="browse-section browse-way">
+  <%= tag.div :class => ["browse-section", "browse-way", { "text-muted" => way.redacted? }] do %>
     <%= render :partial => "browse/common_details", :object => way %>
 
     <% unless way.containing_relation_members.empty? %>
@@ -39,5 +39,5 @@
         </ul>
       </details>
     <% end %>
-  </div>
+  <% end %>
 <% end %>
index cd333d3bfd1dbbcd1e301158274b40dfb7de3844..9ee9f807fb1899f395b2bd0fd9529209bd6ee050 100644 (file)
     &middot;
   <% end %>
     <%= link_to t("browse.view_history"), :action => "#{@type}_history" %>
+  <% if current_user&.moderator? %>
+    &middot;
+    <%= link_to(t("browse.view_unredacted_history"), :action => "#{@type}_history", :params => { :show_redactions => true }) %>
+  <% end %>
   <% if @feature.version > 1 %>
     &middot;
     <%= link_to({ :controller => "old_#{@type.pluralize}", :action => :show, :version => @feature.version }, :class => "icon-link") do %>
index bf11e8f1e20dec49bc014934701d99a82328af88..b557c339b172a9eb5e1c66f5df9e0b961f3f859f 100644 (file)
@@ -8,4 +8,11 @@
   <%= link_to(t("browse.download_xml"), :controller => "api/old_#{@type.pluralize}", :action => "history") %>
   &middot;
   <%= link_to(t("browse.view_details"), :action => @type) %>
+  <% if params[:show_redactions] %>
+    &middot;
+    <%= link_to(t("browse.view_history"), :action => "#{@type}_history") %>
+  <% elsif current_user&.moderator? %>
+    &middot;
+    <%= link_to(t("browse.view_unredacted_history"), :action => "#{@type}_history", :params => { :show_redactions => true }) %>
+  <% end %>
 </div>
index 90be6b7c9007ad17536b615fe3f55d664f5c5068..093a3e7c15c962c45ca5694adbeebf45c71737ba 100644 (file)
@@ -4,28 +4,4 @@
 
 <%= render :partial => "browse/node", :object => @feature %>
 
-<div class='secondary-actions'>
-  <% unless @feature.redacted? %>
-    <%= link_to t("browse.download_xml"), node_version_path(*@feature.id) %>
-    &middot;
-  <% end %>
-  <%= link_to t("browse.view_details"), node_path(@feature.node_id) %>
-</div>
-
-<div class='secondary-actions'>
-  <% if @feature.version > 1 %>
-    <%= link_to old_node_path(@feature.node_id, @feature.version - 1), :class => "icon-link" do %>
-      <%= previous_page_svg_tag :height => 11 %>
-      <%= "#{t('browse.version')} ##{@feature.version - 1}" %>
-    <% end %>
-    &middot;
-  <% end %>
-  <%= link_to t("browse.view_history"), node_history_path(@feature.node_id) %>
-  <% if @feature.version < @feature.current_node.version %>
-    &middot;
-    <%= link_to old_node_path(@feature.node_id, @feature.version + 1), :class => "icon-link" do %>
-      <%= "#{t('browse.version')} ##{@feature.version + 1}" %>
-      <%= next_page_svg_tag :height => 11 %>
-    <% end %>
-  <% end %>
-</div>
+<%= render :partial => "browse/version_actions" %>
index 42e80e6512ac084fe1877e7034ede0a0af3c5cb6..94e3674d8759432efae525c54c215141791c2774 100644 (file)
@@ -4,28 +4,4 @@
 
 <%= render :partial => "browse/relation", :object => @feature %>
 
-<div class='secondary-actions'>
-  <% unless @feature.redacted? %>
-    <%= link_to t("browse.download_xml"), relation_version_path(*@feature.id) %>
-    &middot;
-  <% end %>
-  <%= link_to t("browse.view_details"), relation_path(@feature.relation_id) %>
-</div>
-
-<div class='secondary-actions'>
-  <% if @feature.version > 1 %>
-    <%= link_to old_relation_path(@feature.relation_id, @feature.version - 1), :class => "icon-link" do %>
-      <%= previous_page_svg_tag :height => 11 %>
-      <%= "#{t('browse.version')} ##{@feature.version - 1}" %>
-    <% end %>
-    &middot;
-  <% end %>
-  <%= link_to t("browse.view_history"), relation_history_path(@feature.relation_id) %>
-  <% if @feature.version < @feature.current_relation.version %>
-    &middot;
-    <%= link_to old_relation_path(@feature.relation_id, @feature.version + 1), :class => "icon-link" do %>
-      <%= "#{t('browse.version')} ##{@feature.version + 1}" %>
-      <%= next_page_svg_tag :height => 11 %>
-    <% end %>
-  <% end %>
-</div>
+<%= render :partial => "browse/version_actions" %>
index b16c6b291cdce8ea1dd828b4c96ddc9c7eedcff6..1e4d14c805ceb079d53d3eeba02d858e445d2ac8 100644 (file)
@@ -4,28 +4,4 @@
 
 <%= render :partial => "browse/way", :object => @feature %>
 
-<div class='secondary-actions'>
-  <% unless @feature.redacted? %>
-    <%= link_to t("browse.download_xml"), way_version_path(*@feature.id) %>
-    &middot;
-  <% end %>
-  <%= link_to t("browse.view_details"), way_path(@feature.way_id) %>
-</div>
-
-<div class='secondary-actions'>
-  <% if @feature.version > 1 %>
-    <%= link_to old_way_path(@feature.way_id, @feature.version - 1), :class => "icon-link" do %>
-      <%= previous_page_svg_tag :height => 11 %>
-      <%= "#{t('browse.version')} ##{@feature.version - 1}" %>
-    <% end %>
-    &middot;
-  <% end %>
-  <%= link_to t("browse.view_history"), way_history_path(@feature.way_id) %>
-  <% if @feature.version < @feature.current_way.version %>
-    &middot;
-    <%= link_to old_way_path(@feature.way_id, @feature.version + 1), :class => "icon-link" do %>
-      <%= "#{t('browse.version')} ##{@feature.version + 1}" %>
-      <%= next_page_svg_tag :height => 11 %>
-    <% end %>
-  <% end %>
-</div>
+<%= render :partial => "browse/version_actions" %>
index 6db6e77b4406d0c6b105b916fc77d70327d0d0cc..429786fcc3c13994eca2ff66254a565a4bbf72c6 100644 (file)
@@ -311,6 +311,7 @@ en:
     deleted_ago_by_html: "Deleted %{time_ago} by %{user}"
     edited_ago_by_html: "Edited %{time_ago} by %{user}"
     version: "Version"
+    redacted_version: "Redacted Version"
     in_changeset: "Changeset"
     anonymous: "anonymous"
     no_comment: "(no comment)"
@@ -323,7 +324,10 @@ en:
       other: "%{count} ways"
     download_xml: "Download XML"
     view_history: "View History"
+    view_unredacted_history: "View Unredacted History"
     view_details: "View Details"
+    view_redacted_data: "View Redacted Data"
+    view_redaction_message: "View Redaction Message"
     location: "Location:"
     common_details:
       coordinates_html: "%{latitude}, %{longitude}"
index e74345f6af2016da308ec1c2ca042581366cfed0..fcdd7c752163136e1a6f8eaa650aecb94feb80d0 100644 (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
index 3f2958bd3e49ecd82d04574d5f5eec5b7ed56ab0..a1232be762e9c75b0624deb5fba3b95f2bbfc0ee 100644 (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
index 311e5958a62378d2f326f87344a2ba9d8d3c048a..6eb6db9ddc111a6fb014c5e8cf8c46481f870650 100644 (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
index d428605c51a0a9d9f4198f713675df7ef9ae9860..d28a23ef5a602793d134cae90fb12c5b902f8493 100644 (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