Skip to content

A platform for community discussion. Free, open, simple.

UX: add filter button to user card of deactivated account (#36024)

Yuriy Kurant4793193c0b7b
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index 45f707873dd..d88e12ff1f7 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -126,6 +126,7 @@ class UsersController < ApplicationController
user_serializer = nil
if !current_user&.staff? && [email protected]?
user_serializer = InactiveUserSerializer.new(@user, scope: guardian, root: "user")
+ assign_topic_post_count(user_serializer) if for_card
elsif !guardian.can_see_profile?(@user)
user_serializer = HiddenProfileSerializer.new(@user, scope: guardian, root: "user")
assign_topic_post_count(user_serializer) if for_card
diff --git a/app/serializers/inactive_user_serializer.rb b/app/serializers/inactive_user_serializer.rb
index f76a02e6cf7..e3b13bd4d4e 100644
--- a/app/serializers/inactive_user_serializer.rb
+++ b/app/serializers/inactive_user_serializer.rb
@@ -1,9 +1,15 @@
# frozen_string_literal: true
class InactiveUserSerializer < BasicUserSerializer
- attributes :inactive
+ attr_accessor :topic_post_count
+
+ attributes :inactive, :topic_post_count
def inactive
!object.active?
end
+
+ def include_topic_post_count?
+ topic_post_count.present?
+ end
end
diff --git a/spec/system/page_objects/components/user_card.rb b/spec/system/page_objects/components/user_card.rb
index e655f5a5829..f1ddd0941a0 100644
--- a/spec/system/page_objects/components/user_card.rb
+++ b/spec/system/page_objects/components/user_card.rb
@@ -3,28 +3,39 @@
module PageObjects
module Components
class UserCard < PageObjects::Components::Base
+ USER_CARD_SELECTOR = ".user-card"
+ FILTER_BUTTON_SELECTOR = "#{USER_CARD_SELECTOR} .usercard-controls .d-icon-filter"
+
def visible?
- has_css?("#user-card")
+ has_css?(USER_CARD_SELECTOR)
end
def showing_user?(username)
- has_css?("#user-card.user-card-#{username}")
+ has_css?("#{USER_CARD_SELECTOR}.user-card-#{username}")
end
def has_filter_button?
- has_css?("#user-card .usercard-controls .d-icon-filter")
+ has_css?(FILTER_BUTTON_SELECTOR)
end
def has_no_filter_button?
- has_no_css?("#user-card .usercard-controls .d-icon-filter")
+ has_no_css?(FILTER_BUTTON_SELECTOR)
end
def filter_button_text
- find("#user-card .usercard-controls .d-icon-filter + .d-button-label").text
+ find("#{FILTER_BUTTON_SELECTOR} + .d-button-label").text
+ end
+
+ def click_filter_button
+ find("#{FILTER_BUTTON_SELECTOR} + .d-button-label").click
end
def has_profile_hidden?
- has_css?("#user-card .profile-hidden", visible: true)
+ has_css?("#{USER_CARD_SELECTOR} .profile-hidden", visible: true)
+ end
+
+ def has_inactive_user?
+ has_css?("#{USER_CARD_SELECTOR} .inactive-user", visible: true)
end
end
end
diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb
index e1db87a13ca..f4a76b46626 100644
--- a/spec/system/page_objects/pages/topic.rb
+++ b/spec/system/page_objects/pages/topic.rb
@@ -337,6 +337,10 @@ module PageObjects
within(post_by_number(post)) { yield }
end
+ def has_filtered_notice_text?(text)
+ find(".posts-filtered-notice").has_text?(text, exact: false)
+ end
+
private
def within_topic_footer_buttons
diff --git a/spec/system/user_card_spec.rb b/spec/system/user_card_spec.rb
index 268a4bb9abe..4477f263761 100644
--- a/spec/system/user_card_spec.rb
+++ b/spec/system/user_card_spec.rb
@@ -74,6 +74,34 @@ describe "User Card", type: :system do
expect(user_card).to have_profile_hidden
expect(user_card).to have_filter_button
expect(user_card.filter_button_text).to match(I18n.t("js.topic.filter_to", count: 2))
+
+ user_card.click_filter_button
+ expect(topic_page).to have_filtered_notice_text(
+ I18n.t("js.post.filtered_replies.viewing_posts_by", post_count: 2),
+ )
+ end
+ end
+
+ context "when user is deactivated" do
+ before do
+ another_user.update!(active: false)
+ # Sign in as regular user (not admin) to see deactivated user behavior
+ sign_in(user)
+ end
+
+ it "shows filter button with post count for deactivated user" do
+ topic_page.visit_topic(topic)
+ topic_page.click_post_author_avatar(first_post_by_another_user)
+
+ expect(user_card).to be_showing_user(another_user.username)
+ expect(user_card).to have_inactive_user
+ expect(user_card).to have_filter_button
+ expect(user_card.filter_button_text).to match(I18n.t("js.topic.filter_to", count: 2))
+
+ user_card.click_filter_button
+ expect(topic_page).to have_filtered_notice_text(
+ I18n.t("js.post.filtered_replies.viewing_posts_by", post_count: 2),
+ )
end
end
end