FEATURE: hide muted categories from /categories list (#6531)

This commit is contained in:
Penar Musaraj 2018-10-25 20:34:39 -04:00 committed by Sam
parent d17c8df926
commit ed9c21e42c
2 changed files with 15 additions and 0 deletions

View File

@ -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?

View File

@ -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