FIX: return regular notification level for categories when not set by user
This commit is contained in:
parent
6ce422feab
commit
38269c416d
|
@ -87,13 +87,15 @@ class CategoryList
|
||||||
@categories = @categories.to_a
|
@categories = @categories.to_a
|
||||||
|
|
||||||
category_user = {}
|
category_user = {}
|
||||||
|
default_notification_level = nil
|
||||||
unless @guardian.anonymous?
|
unless @guardian.anonymous?
|
||||||
category_user = Hash[*CategoryUser.where(user: @guardian.user).pluck(:category_id, :notification_level).flatten]
|
category_user = Hash[*CategoryUser.where(user: @guardian.user).pluck(:category_id, :notification_level).flatten]
|
||||||
|
default_notification_level = CategoryUser.notification_levels[:regular]
|
||||||
end
|
end
|
||||||
|
|
||||||
allowed_topic_create = Set.new(Category.topic_create_allowed(@guardian).pluck(:id))
|
allowed_topic_create = Set.new(Category.topic_create_allowed(@guardian).pluck(:id))
|
||||||
@categories.each do |category|
|
@categories.each do |category|
|
||||||
category.notification_level = category_user[category.id]
|
category.notification_level = category_user[category.id] || default_notification_level
|
||||||
category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id)
|
category.permission = CategoryGroup.permission_types[:full] if allowed_topic_create.include?(category.id)
|
||||||
category.has_children = category.subcategories.present?
|
category.has_children = category.subcategories.present?
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,6 +81,28 @@ describe CategoryList do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "notification level" do
|
||||||
|
it "returns 'regular' as default notification level" do
|
||||||
|
category = category_list.categories.find { |c| c.id == topic_category.id }
|
||||||
|
expect(category.notification_level).to eq(NotificationLevels.all[:regular])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns the users notication level" do
|
||||||
|
CategoryUser.set_notification_level_for_category(user, NotificationLevels.all[:watching], topic_category.id)
|
||||||
|
category_list = CategoryList.new(Guardian.new(user))
|
||||||
|
category = category_list.categories.find { |c| c.id == topic_category.id }
|
||||||
|
|
||||||
|
expect(category.notification_level).to eq(NotificationLevels.all[:watching])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns no notication level for anonymous users" do
|
||||||
|
category_list = CategoryList.new(Guardian.new(nil))
|
||||||
|
category = category_list.categories.find { |c| c.id == topic_category.id }
|
||||||
|
|
||||||
|
expect(category.notification_level).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'category order' do
|
describe 'category order' do
|
||||||
|
|
Loading…
Reference in New Issue