]> git.openstreetmap.org Git - rails.git/commitdiff
Add revoke all blocks link
authorAnton Khorev <tony29@yandex.ru>
Wed, 27 Dec 2023 15:16:57 +0000 (18:16 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 7 Jan 2024 12:15:28 +0000 (15:15 +0300)
app/abilities/ability.rb
app/views/users/show.html.erb
config/locales/en.yml
config/routes.rb
test/controllers/user_blocks_controller_test.rb
test/system/user_blocks_test.rb [new file with mode: 0644]

index b9da5d08ac596166124884cc2864eb31155be342..83ab69ee2206eec7b78f122a4006731d74372b48 100644 (file)
@@ -61,7 +61,7 @@ class Ability
           can [:index, :show, :resolve, :ignore, :reopen], Issue
           can :create, IssueComment
           can [:new, :create, :edit, :update, :destroy], Redaction
-          can [:new, :edit, :create, :update, :revoke], UserBlock
+          can [:new, :edit, :create, :update, :revoke, :revoke_all], UserBlock
         end
 
         if user.administrator?
index 0c803ebb03cf3492919d24210c0c6ed4716502c2..253945b9b6d2529d1cbc344453c257f924dcdd7f 100644 (file)
               </li>
             <% end %>
 
+            <% if can?(:revoke_all, UserBlock) and @user.blocks.active.exists? %>
+              <li>
+                <%= link_to t(".revoke_all_blocks"), revoke_all_user_blocks_path(@user) %>
+              </li>
+            <% end %>
+
             <% if can?(:create, UserBlock) %>
               <li>
                 <%= link_to t(".create_block"), new_user_block_path(@user) %>
index 335b8ad84a4bf7bf30cd66e9e9f9730b8f95fd94..8bb239ca55ca11f3b939ba205abc3e2914d00606 100644 (file)
@@ -2790,6 +2790,7 @@ en:
           importer: "Revoke importer access"
       block_history: "Active Blocks"
       moderator_history: "Blocks Given"
+      revoke_all_blocks: "Revoke all blocks"
       comments: "Comments"
       create_block: "Block this User"
       activate_user: "Activate this User"
index 110a67a4984a80b7f17182f92432b01f7d1a7e65..a38f8450ff052517e12238b8fb2e9a581f344d5d 100644 (file)
@@ -321,6 +321,7 @@ OpenStreetMap::Application.routes.draw do
   get "/blocks/new/:display_name" => "user_blocks#new", :as => "new_user_block"
   resources :user_blocks
   match "/blocks/:id/revoke" => "user_blocks#revoke", :via => [:get, :post], :as => "revoke_user_block"
+  match "/user/:display_name/blocks/revoke_all" => "user_blocks#revoke_all", :via => [:get, :post], :as => "revoke_all_user_blocks"
 
   # issues and reports
   resources :issues do
index 2c363be3d9d0566b2fffff1a62697995e2aea5a8..efd16f859ad93176978362846b77ae9cf24c42af 100644 (file)
@@ -54,6 +54,14 @@ class UserBlocksControllerTest < ActionDispatch::IntegrationTest
       { :path => "/user/username/blocks_by", :method => :get },
       { :controller => "user_blocks", :action => "blocks_by", :display_name => "username" }
     )
+    assert_routing(
+      { :path => "/user/username/blocks/revoke_all", :method => :get },
+      { :controller => "user_blocks", :action => "revoke_all", :display_name => "username" }
+    )
+    assert_routing(
+      { :path => "/user/username/blocks/revoke_all", :method => :post },
+      { :controller => "user_blocks", :action => "revoke_all", :display_name => "username" }
+    )
   end
 
   ##
diff --git a/test/system/user_blocks_test.rb b/test/system/user_blocks_test.rb
new file mode 100644 (file)
index 0000000..e1247d6
--- /dev/null
@@ -0,0 +1,38 @@
+require "application_system_test_case"
+
+class ReportNoteTest < ApplicationSystemTestCase
+  test "revoke all link is absent for anonymous users when viewed user has active blocks" do
+    blocked_user = create(:user)
+    create(:user_block, :user => blocked_user)
+
+    visit user_path(blocked_user)
+    assert_no_link "Revoke all blocks"
+  end
+
+  test "revoke all link is absent for regular users when viewed user has active blocks" do
+    blocked_user = create(:user)
+    create(:user_block, :user => blocked_user)
+    sign_in_as(create(:user))
+
+    visit user_path(blocked_user)
+    assert_no_link "Revoke all blocks"
+  end
+
+  test "revoke all link is absent for moderators when viewed user has no active blocks" do
+    blocked_user = create(:user)
+    create(:user_block, :expired, :user => blocked_user)
+    sign_in_as(create(:moderator_user))
+
+    visit user_path(blocked_user)
+    assert_no_link "Revoke all blocks"
+  end
+
+  test "revoke all link is present for moderators when viewed user has active blocks" do
+    blocked_user = create(:user)
+    create(:user_block, :user => blocked_user)
+    sign_in_as(create(:moderator_user))
+
+    visit user_path(blocked_user)
+    assert_link "Revoke all blocks"
+  end
+end