Skip to content

Commit f39f44d

Browse files
committed
Categories page should not show invisible topics
1 parent 42564c9 commit f39f44d

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

app/models/category_featured_topic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def self.feature_topics_for(c)
2323
admin.admin = true
2424
admin.id = -1
2525

26-
query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id)
26+
query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id, visible: true)
2727
results = query.list_category(c)
2828
if results.present?
2929
results.topic_ids.each_with_index do |topic_id, idx|

lib/topic_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ def default_list(list_opts={})
257257
result = result.where('categories.name is null or categories.name <> ?', query_opts[:exclude_category]) if query_opts[:exclude_category]
258258
result = result.where('categories.name = ?', query_opts[:only_category]) if query_opts[:only_category]
259259
result = result.limit(page_size) unless query_opts[:limit] == false
260-
result = result.visible if @user.blank? or @user.regular?
260+
result = result.visible if @opts[:visible] or @user.blank? or @user.regular?
261261
result = result.where('topics.id <> ?', query_opts[:except_topic_id]) if query_opts[:except_topic_id].present?
262262
result = result.offset(query_opts[:page].to_i * page_size) if query_opts[:page].present?
263263

spec/models/category_featured_topic_spec.rb

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,33 @@
55
it { should belong_to :category }
66
it { should belong_to :topic }
77

8-
it "should feature topics for a secure category" do
8+
context 'feature_topics_for' do
9+
let(:user) { Fabricate(:user) }
10+
let(:category) { Fabricate(:category) }
11+
let!(:category_post) { PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.name) }
912

10-
# so much dancing, I am thinking fixures make sense here.
11-
user = Fabricate(:user)
12-
user.change_trust_level!(:basic)
13+
it "should feature topics for a secure category" do
1314

14-
category = Fabricate(:category)
15-
category.deny(:all)
16-
category.allow(Group[:trust_level_1])
17-
category.save
15+
# so much dancing, I am thinking fixures make sense here.
16+
user.change_trust_level!(:basic)
1817

19-
uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
20-
category_post = PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.name)
18+
category.deny(:all)
19+
category.allow(Group[:trust_level_1])
20+
category.save
2121

22-
CategoryFeaturedTopic.feature_topics_for(category)
23-
CategoryFeaturedTopic.count.should == 1
22+
uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
2423

24+
CategoryFeaturedTopic.feature_topics_for(category)
25+
CategoryFeaturedTopic.count.should == 1
26+
27+
end
28+
29+
it 'should not include invisible topics' do
30+
invisible_post = PostCreator.create(user, raw: "Don't look at this post because it's awful.", title: "not visible to anyone", category: category.name)
31+
invisible_post.topic.update_status('visible', false, Fabricate(:admin))
32+
CategoryFeaturedTopic.feature_topics_for(category)
33+
CategoryFeaturedTopic.count.should == 1
34+
end
2535
end
2636

2737
end

0 commit comments

Comments
 (0)