mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
CHANGE: Hide category definition topics unless you are viewing that
category.
This commit is contained in:
parent
13157b9b2e
commit
659546c4e4
|
@ -121,8 +121,7 @@ class TopicQuery
|
|||
end
|
||||
|
||||
def list_category(category)
|
||||
create_list(:category, unordered: true) do |list|
|
||||
list = list.where(category_id: category.id)
|
||||
create_list(:category, unordered: true, category: category.id) do |list|
|
||||
if @user
|
||||
list.order(TopicQuerySQL.order_with_pinned_sql)
|
||||
else
|
||||
|
@ -132,10 +131,8 @@ class TopicQuery
|
|||
end
|
||||
|
||||
def list_new_in_category(category)
|
||||
create_list(:new_in_category, unordered: true) do |list|
|
||||
list.where(category_id: category.id)
|
||||
.by_newest
|
||||
.first(25)
|
||||
create_list(:new_in_category, unordered: true, category: category.id) do |list|
|
||||
list.by_newest.first(25)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -242,6 +239,11 @@ class TopicQuery
|
|||
result = result.listable_topics.includes(category: :topic_only_relative_url)
|
||||
result = result.where('categories.name is null or categories.name <> ?', options[:exclude_category]).references(:categories) if options[:exclude_category]
|
||||
|
||||
# Don't include the category topic unless restricted to that category
|
||||
if options[:category].blank?
|
||||
result = result.where('COALESCE(categories.topic_id, 0) <> topics.id')
|
||||
end
|
||||
|
||||
result = result.limit(options[:per_page]) unless options[:limit] == false
|
||||
result = result.visible if options[:visible] || @user.nil? || @user.regular?
|
||||
result = result.where.not(topics: {id: options[:except_topic_ids]}).references(:topics) if options[:except_topic_ids]
|
||||
|
|
|
@ -28,12 +28,12 @@ describe TopicQuery do
|
|||
Topic.recent(10).count.should == 0
|
||||
|
||||
# mods can see every group and hidden topics
|
||||
TopicQuery.new(moderator).list_latest.topics.count.should == 3
|
||||
TopicQuery.new(moderator).list_latest.topics.count.should == 2
|
||||
|
||||
group.add(user)
|
||||
group.save
|
||||
|
||||
TopicQuery.new(user).list_latest.topics.count.should == 2
|
||||
TopicQuery.new(user).list_latest.topics.count.should == 1
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user