From 1ff7b6217ae596cc2a3b74500ac99e710546a54b Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 27 Dec 2023 19:19:37 +0300 Subject: [PATCH 1/1] Add controls to revoke all blocks page --- app/views/user_blocks/revoke_all.html.erb | 19 ++++++++++++++ config/locales/en.yml | 6 +++++ test/system/user_blocks_test.rb | 31 ++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/app/views/user_blocks/revoke_all.html.erb b/app/views/user_blocks/revoke_all.html.erb index 982792ddd..7fef69b57 100644 --- a/app/views/user_blocks/revoke_all.html.erb +++ b/app/views/user_blocks/revoke_all.html.erb @@ -6,3 +6,22 @@ :block_on => link_to(@user.display_name, user_path(@user)) %> <% end %> + +<% unless @user.blocks.active.empty? %> + + <%= bootstrap_form_for :revoke_all, :url => { :action => "revoke_all" } do |f| %> +
+
+ <%= check_box_tag "confirm", "yes", false, { :class => "form-check-input" } %> + <%= label_tag "confirm", t(".confirm", + :active_blocks => t(".active_blocks", + :count => @user.blocks.active.count)), { :class => "form-check-label" } %> +
+
+ + <%= f.primary t(".revoke") %> + <% end %> + +<% else %> +

<%= t ".empty", :name => @user.display_name %>

+<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 449b6e540..ff1ee8984 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2896,6 +2896,12 @@ en: revoke_all: title: "Revoking all blocks on %{block_on}" heading_html: "Revoking all blocks on %{block_on}" + empty: "%{name} has no active blocks." + confirm: "Are you sure you wish to revoke %{active_blocks}?" + active_blocks: + one: "%{count} active block" + other: "%{count} active blocks" + revoke: "Revoke!" helper: time_future_html: "Ends in %{time}." until_login: "Active until the user logs in." diff --git a/test/system/user_blocks_test.rb b/test/system/user_blocks_test.rb index 66a8befec..957ecb662 100644 --- a/test/system/user_blocks_test.rb +++ b/test/system/user_blocks_test.rb @@ -27,7 +27,17 @@ class ReportNoteTest < ApplicationSystemTestCase assert_no_link "Revoke all blocks" end - test "revoke all link is present and working for moderators when viewed user has active blocks" do + test "revoke all page has no controls when viewed user has no active blocks" do + blocked_user = create(:user) + sign_in_as(create(:moderator_user)) + + visit revoke_all_user_blocks_path(blocked_user) + assert_title "Revoking all blocks on #{blocked_user.display_name}" + assert_text "Revoking all blocks on #{blocked_user.display_name}" + assert_no_button "Revoke!" + end + + test "revoke all link is present and working for moderators when viewed user has one active block" do blocked_user = create(:user) create(:user_block, :user => blocked_user) sign_in_as(create(:moderator_user)) @@ -38,5 +48,24 @@ class ReportNoteTest < ApplicationSystemTestCase click_link "Revoke all blocks" assert_title "Revoking all blocks on #{blocked_user.display_name}" assert_text "Revoking all blocks on #{blocked_user.display_name}" + assert_unchecked_field "Are you sure you wish to revoke 1 active block?" + assert_button "Revoke!" + end + + test "revoke all link is present and working for moderators when viewed user has multiple active blocks" do + blocked_user = create(:user) + create(:user_block, :user => blocked_user) + create(:user_block, :user => blocked_user) + create(:user_block, :expired, :user => blocked_user) + sign_in_as(create(:moderator_user)) + + visit user_path(blocked_user) + assert_link "Revoke all blocks" + + click_link "Revoke all blocks" + assert_title "Revoking all blocks on #{blocked_user.display_name}" + assert_text "Revoking all blocks on #{blocked_user.display_name}" + assert_unchecked_field "Are you sure you wish to revoke 2 active blocks?" + assert_button "Revoke!" end end -- 2.39.5