Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5b3630d

Browse files
FIX: Do not raise an error when in:all search is performed by anon (discourse#9113)
Also improve in:all specs to catch to catch similar failures
1 parent 4b70719 commit 5b3630d

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

lib/search.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def initialize(term, opts = nil)
176176
@search_context = @guardian.user
177177
end
178178

179-
if @search_all_topics
179+
if @search_all_topics && @guardian.user
180180
@opts[:type_filter] = "all_topics"
181181
end
182182

spec/components/search_spec.rb

+17-20
Original file line numberDiff line numberDiff line change
@@ -315,56 +315,53 @@ def create_pm(users:, group: nil)
315315
TopicAllowedUser.create!(user_id: u2.id, topic_id: private_topic.id)
316316

317317
# private only
318-
results = Search.execute('cheese',
319-
type_filter: 'all_topics',
318+
results = Search.execute('in:all cheese',
320319
guardian: Guardian.new(u1))
321320
expect(results.posts.length).to eq(1)
322321

323322
# public only
324-
results = Search.execute('eggs',
325-
type_filter: 'all_topics',
323+
results = Search.execute('in:all eggs',
326324
guardian: Guardian.new(u1))
327325
expect(results.posts.length).to eq(1)
328326

329327
# both
330-
results = Search.execute('spam',
331-
type_filter: 'all_topics',
328+
results = Search.execute('in:all spam',
332329
guardian: Guardian.new(u1))
333330
expect(results.posts.length).to eq(2)
334331

332+
# for anon
333+
results = Search.execute('in:all spam',
334+
guardian: Guardian.new)
335+
expect(results.posts.length).to eq(1)
336+
335337
# nonparticipatory user
336-
results = Search.execute('cheese',
337-
type_filter: 'all_topics',
338+
results = Search.execute('in:all cheese',
338339
guardian: Guardian.new(u3))
339340
expect(results.posts.length).to eq(0)
340341

341-
results = Search.execute('eggs',
342-
type_filter: 'all_topics',
342+
results = Search.execute('in:all eggs',
343343
guardian: Guardian.new(u3))
344344
expect(results.posts.length).to eq(1)
345345

346-
results = Search.execute('spam',
347-
type_filter: 'all_topics',
346+
results = Search.execute('in:all spam',
348347
guardian: Guardian.new(u3))
349348
expect(results.posts.length).to eq(1)
350349

351350
# Admin doesn't see private topic
352-
results = Search.execute('spam',
353-
type_filter: 'all_topics',
351+
results = Search.execute('in:all spam',
354352
guardian: Guardian.new(u4))
355353
expect(results.posts.length).to eq(1)
356354

357355
# same keyword for different users
358-
results = Search.execute('ham',
359-
type_filter: 'all_topics',
356+
results = Search.execute('in:all ham',
360357
guardian: Guardian.new(u1))
361358
expect(results.posts.length).to eq(2)
362-
results = Search.execute('ham',
363-
type_filter: 'all_topics',
359+
360+
results = Search.execute('in:all ham',
364361
guardian: Guardian.new(u2))
365362
expect(results.posts.length).to eq(2)
366-
results = Search.execute('ham',
367-
type_filter: 'all_topics',
363+
364+
results = Search.execute('in:all ham',
368365
guardian: Guardian.new(u3))
369366
expect(results.posts.length).to eq(1)
370367
end

0 commit comments

Comments
 (0)