From: Anton Khorev Date: Wed, 27 Dec 2023 15:16:57 +0000 (+0300) Subject: Add revoke all blocks link X-Git-Tag: live~880^2~4 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/8682b58154b0d42cb0dcc9f85efa806bea68210c?ds=sidebyside;hp=-c Add revoke all blocks link --- 8682b58154b0d42cb0dcc9f85efa806bea68210c diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index b9da5d08a..83ab69ee2 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -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? diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 0c803ebb0..253945b9b 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -101,6 +101,12 @@ <% end %> + <% if can?(:revoke_all, UserBlock) and @user.blocks.active.exists? %> +
  • + <%= link_to t(".revoke_all_blocks"), revoke_all_user_blocks_path(@user) %> +
  • + <% end %> + <% if can?(:create, UserBlock) %>
  • <%= link_to t(".create_block"), new_user_block_path(@user) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 335b8ad84..8bb239ca5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/config/routes.rb b/config/routes.rb index 110a67a49..a38f8450f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/controllers/user_blocks_controller_test.rb b/test/controllers/user_blocks_controller_test.rb index 2c363be3d..efd16f859 100644 --- a/test/controllers/user_blocks_controller_test.rb +++ b/test/controllers/user_blocks_controller_test.rb @@ -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 index 000000000..e1247d6a4 --- /dev/null +++ b/test/system/user_blocks_test.rb @@ -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