discourse/app/serializers/concerns/user_sidebar_mixin.rb
Alan Guo Xiang Tan 0a56274596
FIX: Seed all categories and tags configured as defaults for nav menu (#22793)
Context of this change:

There are two site settings which an admin can configured to set the
default categories and tags that are shown for a new user. `default_navigation_menu_categories`
is used to determine the default categories while
`default_navigation_menu_tags` is used to determine the default tags.

Prior to this change when seeding the defaults, we will filter out the
categories/tags that the user do not have permission to see. However,
this means that when the user does eventually gain permission down the
line, the default categories and tags do not appear.

What does this change do?

With this commit, we have changed it such that all the categories and tags
configured in the `default_navigation_menu_categories` and
`default_navigation_menu_tags` site settings are seeded regardless of
whether the user's visibility of the categories or tags. During
serialization, we will then filter out the categories and tags which the
user does not have visibility of.
2023-07-27 10:52:33 +08:00

49 lines
1.0 KiB
Ruby

# frozen_string_literal: true
module UserSidebarMixin
include NavigationMenuTagsMixin
def sidebar_tags
serialize_tags(object.visible_sidebar_tags(scope))
end
def display_sidebar_tags
DiscourseTagging.filter_visible(Tag, scope).exists?
end
def include_display_sidebar_tags?
include_sidebar_tags?
end
def include_sidebar_tags?
SiteSetting.tagging_enabled && sidebar_navigation_menu?
end
def sidebar_category_ids
object.secured_sidebar_category_ids(scope)
end
def include_sidebar_category_ids?
sidebar_navigation_menu?
end
def sidebar_sections
object
.sidebar_sections
.order(created_at: :asc)
.includes(sidebar_section_links: :linkable)
.map { |section| SidebarSectionSerializer.new(section, root: false) }
end
def include_sidebar_sections?
sidebar_navigation_menu?
end
private
def sidebar_navigation_menu?
!SiteSetting.legacy_navigation_menu? ||
%w[sidebar header_dropdown].include?(options[:navigation_menu_param])
end
end