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
|
find_categories
|
||||||
|
|
||||||
prune_empty
|
prune_empty
|
||||||
|
prune_muted
|
||||||
find_user_data
|
find_user_data
|
||||||
sort_unpinned
|
sort_unpinned
|
||||||
trim_results
|
trim_results
|
||||||
|
@ -136,6 +137,10 @@ class CategoryList
|
||||||
@categories.delete_if { |c| c.uncategorized? && c.displayable_topics.blank? }
|
@categories.delete_if { |c| c.uncategorized? && c.displayable_topics.blank? }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prune_muted
|
||||||
|
@categories.delete_if { |c| c.notification_level == CategoryUser.notification_levels[:muted] }
|
||||||
|
end
|
||||||
|
|
||||||
# Attach some data for serialization to each topic
|
# Attach some data for serialization to each topic
|
||||||
def find_user_data
|
def find_user_data
|
||||||
if @guardian.current_user && @all_topics.present?
|
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)
|
expect(CategoryList.new(Guardian.new(nil), include_topics: true).categories.find { |x| x.name == private_cat.name }).to eq(nil)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "with a category" do
|
context "with a category" do
|
||||||
|
|
Loading…
Reference in New Issue