diff --git a/app/components/moderation/users/index_component.html.erb b/app/components/moderation/users/index_component.html.erb
index d5b995825..ef5cb7db2 100644
--- a/app/components/moderation/users/index_component.html.erb
+++ b/app/components/moderation/users/index_component.html.erb
@@ -19,7 +19,7 @@
<% if user.hidden? %>
- <%= t("moderation.users.index.hidden") %>
+ <%= status(user) %>
<% else %>
<%= render Admin::TableActionsComponent.new(user, actions: []) do |actions| %>
<%= actions.action(
diff --git a/app/components/moderation/users/index_component.rb b/app/components/moderation/users/index_component.rb
index 8e738032c..ddfa20e85 100644
--- a/app/components/moderation/users/index_component.rb
+++ b/app/components/moderation/users/index_component.rb
@@ -4,4 +4,14 @@ class Moderation::Users::IndexComponent < ApplicationComponent
def initialize(users)
@users = users
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
diff --git a/config/locales/en/moderation.yml b/config/locales/en/moderation.yml
index ff0fb98c6..cdf884c4c 100644
--- a/config/locales/en/moderation.yml
+++ b/config/locales/en/moderation.yml
@@ -104,7 +104,6 @@ en:
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
title: Block users
diff --git a/config/locales/es/moderation.yml b/config/locales/es/moderation.yml
index b5580317a..706b61735 100644
--- a/config/locales/es/moderation.yml
+++ b/config/locales/es/moderation.yml
@@ -104,7 +104,6 @@ es:
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
title: Bloquear usuarios
diff --git a/spec/components/moderation/users/index_component_spec.rb b/spec/components/moderation/users/index_component_spec.rb
index 49648ff7d..da1f8505f 100644
--- a/spec/components/moderation/users/index_component_spec.rb
+++ b/spec/components/moderation/users/index_component_spec.rb
@@ -13,17 +13,90 @@ describe Moderation::Users::IndexComponent, controller: Moderation::UsersControl
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
- it "shows 'blocked' for hidden users" do
- create(:user, :hidden)
+ 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
+ render_inline component
- page.find("table") do |table|
- expect(table).to have_content "Blocked"
- expect(table).not_to have_button
+ 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)
+
+ render_inline component
+
+ page.find("table") do |table|
+ expect(table).to have_content "Blocked"
+ 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
diff --git a/spec/system/moderation/users_spec.rb b/spec/system/moderation/users_spec.rb
index d9e92e5b4..42247e333 100644
--- a/spec/system/moderation/users_spec.rb
+++ b/spec/system/moderation/users_spec.rb
@@ -75,4 +75,23 @@ describe "Moderate users" do
expect(page).to have_content "Blocked"
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
|