Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit db3ca2c

Browse files
committed
this ensures that under no conditions PMs will be included
1 parent 9aede89 commit db3ca2c

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

lib/utils/research/filter.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,12 @@ def limit_by_user!(limit)
235235
end
236236

237237
def search
238-
filtered = Post.secured(@guardian).joins(:topic).merge(Topic.secured(@guardian))
238+
filtered =
239+
Post
240+
.secured(@guardian)
241+
.joins(:topic)
242+
.merge(Topic.secured(@guardian))
243+
.where("topics.archetype = 'regular'")
239244
original_filtered = filtered
240245

241246
@filters.each do |filter_block, match_data|

spec/lib/utils/research/filter_spec.rb

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
describe DiscourseAi::Utils::Research::Filter do
44
describe "integration tests" do
5-
before_all { SiteSetting.min_topic_title_length = 3 }
5+
before_all do
6+
SiteSetting.min_topic_title_length = 3
7+
SiteSetting.min_personal_message_title_length = 3
8+
end
69

710
fab!(:user)
811

@@ -51,6 +54,46 @@
5154
fab!(:feature_bug_post) { Fabricate(:post, topic: feature_bug_topic, user: user) }
5255
fab!(:no_tag_post) { Fabricate(:post, topic: no_tag_topic, user: user) }
5356

57+
describe "security filtering" do
58+
fab!(:secure_group) { Fabricate(:group) }
59+
fab!(:secure_category) { Fabricate(:category, name: "Secure") }
60+
61+
fab!(:secure_topic) do
62+
secure_category.set_permissions(secure_group => :readonly)
63+
secure_category.save!
64+
Fabricate(
65+
:topic,
66+
category: secure_category,
67+
user: user,
68+
title: "This is a secret Secret Topic",
69+
)
70+
end
71+
72+
fab!(:secure_post) { Fabricate(:post, topic: secure_topic, user: user) }
73+
74+
fab!(:pm_topic) { Fabricate(:private_message_topic, user: user) }
75+
fab!(:pm_post) { Fabricate(:post, topic: pm_topic, user: user) }
76+
77+
it "omits secure categories when no guardian is supplied" do
78+
filter = described_class.new("")
79+
expect(filter.search.pluck(:id)).not_to include(secure_post.id)
80+
81+
user.groups << secure_group
82+
guardian = Guardian.new(user)
83+
filter_with_guardian = described_class.new("", guardian: guardian)
84+
expect(filter_with_guardian.search.pluck(:id)).to include(secure_post.id)
85+
end
86+
87+
it "omits PMs unconditionally" do
88+
filter = described_class.new("")
89+
expect(filter.search.pluck(:id)).not_to include(pm_post.id)
90+
91+
guardian = Guardian.new(user)
92+
filter_with_guardian = described_class.new("", guardian: guardian)
93+
expect(filter_with_guardian.search.pluck(:id)).not_to include(pm_post.id)
94+
end
95+
end
96+
5497
describe "tag filtering" do
5598
it "correctly filters posts by tags" do
5699
filter = described_class.new("tag:feature")

0 commit comments

Comments
 (0)