Ask for confirmation when hiding/blocking users

In the moderation section there's no clear indicator as to what the
"Hide" and "Block" buttons do and the difference between them.

Since we're using confirmation dialogs in all moderation actions except
these ones, we're adding them here as well, so the difference will
appear in the dialog.

This isn't a very good solution, though, since the confirmation dialog
comes after clicking the button and users have already been wondering
whether clicking that button will be the right choice. A better solution
would be making the purpose clear before the button is clicked, although
that's something we don't do anywhere in the admin/moderation sections.
This commit is contained in:
Javi Martín
2021-12-29 20:33:15 +01:00
parent 992da1fef3
commit a31e73bf23
9 changed files with 36 additions and 9 deletions

View File

@@ -68,6 +68,8 @@ class Admin::ActionComponent < ApplicationComponent
else
t("admin.actions.confirm_action", action: text, name: record_name)
end
elsif options[:confirm].respond_to?(:call)
options[:confirm].call(record_name)
else
options[:confirm]
end

View File

@@ -17,7 +17,7 @@
path: block_moderation_user_path(author),
id: dom_id(author, "#{dom_id(record)}_block_author"),
method: :put,
confirm: true
confirm: ->(name) { t("moderation.users.index.confirm_block", name: name) }
) %>
<% end %>
</div>

View File

@@ -22,8 +22,18 @@
<%= t("moderation.users.index.hidden") %>
<% else %>
<%= render Admin::TableActionsComponent.new(user, actions: []) do |actions| %>
<%= actions.action(:hide, text: t("moderation.users.index.hide"), method: :put) %>
<%= actions.action(:block, text: t("moderation.users.index.block"), method: :put) %>
<%= actions.action(
:hide,
text: t("moderation.users.index.hide"),
confirm: ->(name) { t("moderation.users.index.confirm_hide", name: name) },
method: :put
) %>
<%= actions.action(
:block,
text: t("moderation.users.index.block"),
confirm: ->(name) { t("moderation.users.index.confirm_block", name: name) },
method: :put
) %>
<% end %>
<% end %>
</td>

View File

@@ -102,6 +102,8 @@ en:
users:
index:
block: Block
confirm_block: "Are you sure? This will hide the user \"%{name}\" and all their contents."
confirm_hide: "Are you sure? This will hide the user \"%{name}\" without hiding their contents."
hidden: Blocked
hide: Hide
search_placeholder: email or name of user

View File

@@ -102,6 +102,8 @@ es:
users:
index:
block: Bloquear
confirm_block: "¿Seguro? Esto ocultará a \"%{name}\" así como todos sus contenidos."
confirm_hide: "¿Seguro? Esto ocultará a \"%{name}\" sin ocultar sus contenidos."
hidden: Bloqueado
hide: Ocultar
search_placeholder: email o nombre de usuario

View File

@@ -217,7 +217,9 @@ describe "Admin activity" do
visit proposal_path(proposal)
within("#proposal_#{proposal.id}") do
accept_confirm("Are you sure? Block author \"#{proposal.author.name}\"") { click_button "Block author" }
accept_confirm("Are you sure? This will hide the user \"#{proposal.author.name}\" and all their contents.") do
click_button "Block author"
end
expect(page).to have_current_path(proposals_path)
end
@@ -239,9 +241,11 @@ describe "Admin activity" do
visit moderation_users_path(search: user.username)
within("#moderation_users") do
click_button "Block"
accept_confirm { click_button "Block" }
end
expect(page).to have_content "The user has been blocked"
visit admin_activity_path
within first("tbody tr") do

View File

@@ -13,7 +13,9 @@ describe "Admin hidden comments", :admin do
visit proposal_path(proposal)
within("#proposal_#{proposal.id}") do
accept_confirm("Are you sure? Block author \"#{proposal.author.name}\"") { click_button "Block author" }
accept_confirm("Are you sure? This will hide the user \"#{proposal.author.name}\" and all their contents.") do
click_button "Block author"
end
end
expect(page).to have_current_path proposals_path

View File

@@ -23,7 +23,9 @@ describe "Moderate budget investments" do
login_as(mod.user)
visit budget_investment_path(budget, investment)
accept_confirm("Are you sure? Block author \"#{investment.author.name}\"") { click_button "Block author" }
accept_confirm("Are you sure? This will hide the user \"#{investment.author.name}\" and all their contents.") do
click_button "Block author"
end
expect(page).to have_current_path(budget_investments_path(budget))
expect(page).not_to have_content(investment.title)

View File

@@ -24,7 +24,9 @@ describe "Moderate users" do
visit debate_path(debate1)
within("#debate_#{debate1.id}") do
accept_confirm("Are you sure? Block author \"#{debate1.author.name}\"") { click_button "Block author" }
accept_confirm("Are you sure? This will hide the user \"#{debate1.author.name}\" and all their contents.") do
click_button "Block author"
end
end
expect(page).to have_current_path(debates_path)
@@ -64,7 +66,8 @@ describe "Moderate users" do
within("#moderation_users") do
expect(page).to have_content citizen.name
expect(page).not_to have_content "Blocked"
click_button "Block"
accept_confirm { click_button "Block" }
end
within("#moderation_users") do