|
2 | 2 |
|
3 | 3 | describe DiscourseAi::Utils::Research::Filter do
|
4 | 4 | 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 |
6 | 9 |
|
7 | 10 | fab!(:user)
|
8 | 11 |
|
|
51 | 54 | fab!(:feature_bug_post) { Fabricate(:post, topic: feature_bug_topic, user: user) }
|
52 | 55 | fab!(:no_tag_post) { Fabricate(:post, topic: no_tag_topic, user: user) }
|
53 | 56 |
|
| 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 | + |
54 | 97 | describe "tag filtering" do
|
55 | 98 | it "correctly filters posts by tags" do
|
56 | 99 | filter = described_class.new("tag:feature")
|
|
76 | 119 | filter = described_class.new("category:Announcements")
|
77 | 120 | expect(filter.search.pluck(:id)).to contain_exactly(feature_post.id, bug_post.id)
|
78 | 121 |
|
| 122 | + # it can tack on topics |
| 123 | + filter = |
| 124 | + described_class.new( |
| 125 | + "category:Announcements topic:#{feature_bug_post.topic.id},#{no_tag_post.topic.id}", |
| 126 | + ) |
| 127 | + expect(filter.search.pluck(:id)).to contain_exactly( |
| 128 | + feature_post.id, |
| 129 | + bug_post.id, |
| 130 | + feature_bug_post.id, |
| 131 | + no_tag_post.id, |
| 132 | + ) |
| 133 | + |
79 | 134 | filter = described_class.new("category:Announcements,Feedback")
|
80 | 135 | expect(filter.search.pluck(:id)).to contain_exactly(
|
81 | 136 | feature_post.id,
|
|
0 commit comments