From 554ff07786a81ed55c902c074d5ba787cfda0a3b Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 7 Jan 2022 17:06:11 +0530 Subject: [PATCH] FIX: when composing a message do not suggest deleted posts users (#15488) --- app/models/user_search.rb | 2 +- spec/models/user_search_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/user_search.rb b/app/models/user_search.rb index 2b60c5c3e8e..c7d4fdff8d5 100644 --- a/app/models/user_search.rb +++ b/app/models/user_search.rb @@ -83,7 +83,7 @@ class UserSearch # 2. in topic if @topic_id in_topic = filtered_by_term_users - .where('users.id IN (SELECT user_id FROM posts WHERE topic_id = ? AND post_type = ?)', @topic_id, Post.types[:regular]) + .where('users.id IN (SELECT user_id FROM posts WHERE topic_id = ? AND post_type = ? AND deleted_at IS NULL)', @topic_id, Post.types[:regular]) if @searching_user.present? in_topic = in_topic.where('users.id <> ?', @searching_user.id) diff --git a/spec/models/user_search_spec.rb b/spec/models/user_search_spec.rb index ea011ac9209..5d8dbbee637 100644 --- a/spec/models/user_search_spec.rb +++ b/spec/models/user_search_spec.rb @@ -176,6 +176,12 @@ describe UserSearch do expect(results).to eq [mr_blue.username] end + it "does not include deleted posts users" do + post4.trash! + results = search_for("", topic_id: topic.id) + expect(results).to eq [mr_orange, mr_b].map(&:username) + end + it "only reveals topic participants to people with permission" do pm_topic = Fabricate(:private_message_post).topic