]> git.openstreetmap.org Git - rails.git/commitdiff
Add link to unredacted element history for moderators
authorAnton Khorev <tony29@yandex.ru>
Sat, 4 Nov 2023 18:14:29 +0000 (21:14 +0300)
committerAnton Khorev <tony29@yandex.ru>
Fri, 1 Mar 2024 08:21:49 +0000 (11:21 +0300)
app/controllers/browse_controller.rb
app/views/browse/feature.html.erb
app/views/browse/history.html.erb
config/locales/en.yml
test/controllers/browse_controller_test.rb

index 88871a9e127b03b17249f86ad8b8b16b851d1f5d..e842d4872bf753a5c3993f7bb93455be84643c9b 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
 
@@ -77,4 +78,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 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 2f1e4d016f717f96bb0f133456acea3e1348af62..a674487a693d347e2ea5d963a1cd73d744d52c9e 100644 (file)
@@ -329,6 +329,7 @@ en:
       other: "%{count} ways"
     download_xml: "Download XML"
     view_history: "View History"
+    view_unredacted_history: "View Unredacted History"
     view_details: "View Details"
     location: "Location:"
     common_details:
index 2bb743636ce9d5f5845d0922ddf8a65c5eecf06a..a6fd3ef8d65ffcb63cfd241f1d4f857ed7675505 100644 (file)
@@ -235,6 +235,87 @@ class BrowseControllerTest < ActionDispatch::IntegrationTest
     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
+
   private
 
   # This is a convenience method for most of the above checks