Skip to content

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

FIX: exclude links from hidden posts in user summary (#31504)

Régis Hanol26b042883787
diff --git a/app/models/user_summary.rb b/app/models/user_summary.rb
index 311785067b1..666c3e39c3c 100644
--- a/app/models/user_summary.rb
+++ b/app/models/user_summary.rb
@@ -33,7 +33,7 @@ class UserSummary
def links
TopicLink
.joins(:topic, :post)
- .where(posts: { user_id: @user.id })
+ .where(posts: { user_id: @user.id, hidden: false })
.includes(:topic, :post)
.where("posts.post_type IN (?)", Topic.visible_post_types(@guardian && @guardian.user))
.merge(Topic.listable_topics.visible.secured(@guardian))
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index f5fce3757bf..fe5451d7881 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -4351,6 +4351,42 @@ RSpec.describe UsersController do
expect(json["user_summary"]["post_count"]).to eq(1)
end
+ context "when user has hidden posts with links" do
+ fab!(:user) { Fabricate(:user, trust_level: 4) }
+ fab!(:topic) { Fabricate(:topic, user:) }
+ fab!(:visible_post) do
+ create_post(topic:, user:, raw: "Check out [this link](https://visible-link.com)")
+ end
+ fab!(:another_visible_post) do
+ create_post(topic:, user:, raw: "And [another link](https://another-visible-link.com)")
+ end
+ fab!(:hidden_post) do
+ create_post(topic:, user:, raw: "This has a [hidden link](https://hidden-link.com)")
+ end
+ fab!(:deleted_post) do
+ create_post(topic:, user:, raw: "This has a [deleted link](https://deleted-link.com)")
+ end
+
+ before do
+ deleted_post.trash!
+ hidden_post.hide!(PostActionType.types[:off_topic])
+ sign_in(user)
+ end
+
+ it "doesn't include links from hidden or deleted posts" do
+ get "/u/#{user.username}/summary.json"
+
+ expect(response.status).to eq(200)
+
+ links = response.parsed_body["user_summary"]["links"]
+
+ expect(links.map { _1["url"] }).to contain_exactly(
+ "https://visible-link.com",
+ "https://another-visible-link.com",
+ )
+ end
+ end
+
context "when `hide_user_profiles_from_public` site setting is enabled" do
before { SiteSetting.hide_user_profiles_from_public = true }