mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-02 11:59:17 -05:00
Categories page should not show invisible topics
This commit is contained in:
parent
42564c9ce7
commit
f39f44ddbf
3 changed files with 24 additions and 14 deletions
|
@ -23,7 +23,7 @@ class CategoryFeaturedTopic < ActiveRecord::Base
|
||||||
admin.admin = true
|
admin.admin = true
|
||||||
admin.id = -1
|
admin.id = -1
|
||||||
|
|
||||||
query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id)
|
query = TopicQuery.new(admin, per_page: SiteSetting.category_featured_topics, except_topic_id: c.topic_id, visible: true)
|
||||||
results = query.list_category(c)
|
results = query.list_category(c)
|
||||||
if results.present?
|
if results.present?
|
||||||
results.topic_ids.each_with_index do |topic_id, idx|
|
results.topic_ids.each_with_index do |topic_id, idx|
|
||||||
|
|
|
@ -257,7 +257,7 @@ class TopicQuery
|
||||||
result = result.where('categories.name is null or categories.name <> ?', query_opts[:exclude_category]) if query_opts[:exclude_category]
|
result = result.where('categories.name is null or categories.name <> ?', query_opts[:exclude_category]) if query_opts[:exclude_category]
|
||||||
result = result.where('categories.name = ?', query_opts[:only_category]) if query_opts[:only_category]
|
result = result.where('categories.name = ?', query_opts[:only_category]) if query_opts[:only_category]
|
||||||
result = result.limit(page_size) unless query_opts[:limit] == false
|
result = result.limit(page_size) unless query_opts[:limit] == false
|
||||||
result = result.visible if @user.blank? or @user.regular?
|
result = result.visible if @opts[:visible] or @user.blank? or @user.regular?
|
||||||
result = result.where('topics.id <> ?', query_opts[:except_topic_id]) if query_opts[:except_topic_id].present?
|
result = result.where('topics.id <> ?', query_opts[:except_topic_id]) if query_opts[:except_topic_id].present?
|
||||||
result = result.offset(query_opts[:page].to_i * page_size) if query_opts[:page].present?
|
result = result.offset(query_opts[:page].to_i * page_size) if query_opts[:page].present?
|
||||||
|
|
||||||
|
|
|
@ -5,24 +5,34 @@ describe CategoryFeaturedTopic do
|
||||||
it { should belong_to :category }
|
it { should belong_to :category }
|
||||||
it { should belong_to :topic }
|
it { should belong_to :topic }
|
||||||
|
|
||||||
|
context 'feature_topics_for' do
|
||||||
|
let(:user) { Fabricate(:user) }
|
||||||
|
let(:category) { Fabricate(:category) }
|
||||||
|
let!(:category_post) { PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.name) }
|
||||||
|
|
||||||
it "should feature topics for a secure category" do
|
it "should feature topics for a secure category" do
|
||||||
|
|
||||||
# so much dancing, I am thinking fixures make sense here.
|
# so much dancing, I am thinking fixures make sense here.
|
||||||
user = Fabricate(:user)
|
|
||||||
user.change_trust_level!(:basic)
|
user.change_trust_level!(:basic)
|
||||||
|
|
||||||
category = Fabricate(:category)
|
|
||||||
category.deny(:all)
|
category.deny(:all)
|
||||||
category.allow(Group[:trust_level_1])
|
category.allow(Group[:trust_level_1])
|
||||||
category.save
|
category.save
|
||||||
|
|
||||||
uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
|
uncategorized_post = PostCreator.create(user, raw: "this is my new post 123 post", title: "hello world")
|
||||||
category_post = PostCreator.create(user, raw: "I put this post in the category", title: "categorize THIS", category: category.name)
|
|
||||||
|
|
||||||
CategoryFeaturedTopic.feature_topics_for(category)
|
CategoryFeaturedTopic.feature_topics_for(category)
|
||||||
CategoryFeaturedTopic.count.should == 1
|
CategoryFeaturedTopic.count.should == 1
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should not include invisible topics' do
|
||||||
|
invisible_post = PostCreator.create(user, raw: "Don't look at this post because it's awful.", title: "not visible to anyone", category: category.name)
|
||||||
|
invisible_post.topic.update_status('visible', false, Fabricate(:admin))
|
||||||
|
CategoryFeaturedTopic.feature_topics_for(category)
|
||||||
|
CategoryFeaturedTopic.count.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue