Differentiate between blocked and hidden users

It was a bit confusing to press the "hide" button and then see the user
listed as "blocked". Some moderators might think they accidentally
pressed the wrong button.
This commit is contained in:
Javi Martín
2021-12-30 14:29:03 +01:00
parent e9d9789c25
commit efb7ad9e42
6 changed files with 109 additions and 9 deletions

View File

@@ -19,7 +19,7 @@
</td> </td>
<td> <td>
<% if user.hidden? %> <% if user.hidden? %>
<%= t("moderation.users.index.hidden") %> <%= status(user) %>
<% else %> <% else %>
<%= render Admin::TableActionsComponent.new(user, actions: []) do |actions| %> <%= render Admin::TableActionsComponent.new(user, actions: []) do |actions| %>
<%= actions.action( <%= actions.action(

View File

@@ -4,4 +4,14 @@ class Moderation::Users::IndexComponent < ApplicationComponent
def initialize(users) def initialize(users)
@users = users @users = users
end end
private
def status(user)
t("admin.activity.show.actions.#{activity_action(user)}")
end
def activity_action(user)
Activity.where(actionable: user, action: [:hide, :block]).last&.action || "block"
end
end end

View File

@@ -104,7 +104,6 @@ en:
block: Block block: Block
confirm_block: "Are you sure? This will hide the user \"%{name}\" and all their contents." 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." confirm_hide: "Are you sure? This will hide the user \"%{name}\" without hiding their contents."
hidden: Blocked
hide: Hide hide: Hide
search_placeholder: email or name of user search_placeholder: email or name of user
title: Block users title: Block users

View File

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

View File

@@ -13,17 +13,90 @@ describe Moderation::Users::IndexComponent, controller: Moderation::UsersControl
expect(table).to have_button "Hide" expect(table).to have_button "Hide"
expect(table).to have_button "Block" expect(table).to have_button "Block"
expect(table).not_to have_content "Blocked" expect(table).not_to have_content "Blocked"
expect(table).not_to have_content "Hidden"
end end
end end
it "shows 'blocked' for hidden users" do context "for hidden users" do
it "shows 'blocked' when the user has been blocked" do
user = create(:user, :hidden)
Activity.log(nil, :block, user)
render_inline component
page.find("table") do |table|
expect(table).to have_content "Blocked"
expect(table).not_to have_content "Hidden"
expect(table).not_to have_button
end
end
it "shows 'hidden' when the user has been hidden" do
user = create(:user, :hidden)
Activity.log(nil, :hide, user)
render_inline component
page.find("table") do |table|
expect(table).to have_content "Hidden"
expect(table).not_to have_content "Blocked"
expect(table).not_to have_button
end
end
it "shows 'blocked' when there are no activities to hide the user" do
create(:user, :hidden) create(:user, :hidden)
render_inline component render_inline component
page.find("table") do |table| page.find("table") do |table|
expect(table).to have_content "Blocked" expect(table).to have_content "Blocked"
expect(table).not_to have_button end
end
it "is not affected by activities for other users" do
blocked = create(:user, :hidden, username: "Very bad user")
hidden = create(:user, :hidden, username: "Slightly bad user")
Activity.log(nil, :block, blocked)
Activity.log(nil, :hide, hidden)
render_inline component
page.find("tr", text: "Very bad user") do |row|
expect(row).to have_content "Blocked"
end
page.find("tr", text: "Slightly bad user") do |row|
expect(row).to have_content "Hidden"
end
end
it "doesn't consider activities other than block or hide" do
user = create(:user, :hidden)
Activity.log(nil, :block, user)
Activity.log(nil, :restore, user)
render_inline component
page.find("table") do |table|
expect(table).to have_content "Blocked"
end
end
it "shows actions after the user has been restored" do
user = create(:user, :hidden)
Activity.log(nil, :block, user)
user.restore
render_inline component
page.find("table") do |table|
expect(table).to have_button "Hide"
expect(table).to have_button "Block"
expect(table).not_to have_content "Blocked"
expect(table).not_to have_content "Hidden"
end
end end
end end
end end

View File

@@ -75,4 +75,23 @@ describe "Moderate users" do
expect(page).to have_content "Blocked" expect(page).to have_content "Blocked"
end end
end end
scenario "Hide users in the moderation section" do
create(:user, username: "Rick")
login_as(create(:moderator).user)
visit moderation_users_path(search: "Rick")
within("#moderation_users") do
accept_confirm('This will hide the user "Rick" without hiding their contents') do
click_button "Hide"
end
end
expect(page).to have_content "The user has been hidden"
within("#moderation_users") do
expect(page).to have_content "Hidden"
end
end
end end