mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 14:53:39 +08:00
FEATURE: hide muted categories from /categories list (#6531)
This commit is contained in:
parent
d17c8df926
commit
ed9c21e42c
|
@ -20,6 +20,7 @@ class CategoryList
|
|||
find_categories
|
||||
|
||||
prune_empty
|
||||
prune_muted
|
||||
find_user_data
|
||||
sort_unpinned
|
||||
trim_results
|
||||
|
@ -136,6 +137,10 @@ class CategoryList
|
|||
@categories.delete_if { |c| c.uncategorized? && c.displayable_topics.blank? }
|
||||
end
|
||||
|
||||
def prune_muted
|
||||
@categories.delete_if { |c| c.notification_level == CategoryUser.notification_levels[:muted] }
|
||||
end
|
||||
|
||||
# Attach some data for serialization to each topic
|
||||
def find_user_data
|
||||
if @guardian.current_user && @all_topics.present?
|
||||
|
|
|
@ -47,6 +47,16 @@ describe CategoryList do
|
|||
expect(CategoryList.new(Guardian.new(nil), include_topics: true).categories.find { |x| x.name == private_cat.name }).to eq(nil)
|
||||
end
|
||||
|
||||
it "properly hide muted categories" do
|
||||
cat_muted = Fabricate(:category)
|
||||
CategoryUser.create!(user_id: user.id,
|
||||
category_id: cat_muted.id,
|
||||
notification_level: CategoryUser.notification_levels[:muted])
|
||||
|
||||
# uncategorized + cat_muted for admin
|
||||
expect(CategoryList.new(Guardian.new admin).categories.count).to eq(2)
|
||||
expect(CategoryList.new(Guardian.new user).categories.count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
context "with a category" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user