FEATURE: default sidebar categories and tags (#17939)

Ability to set up default sidebar categories and tags for authenticated users
This commit is contained in:
Krzysztof Kotlarek
2022-08-22 08:46:20 +10:00
committed by GitHub
parent 49fa2e93c2
commit caab916569
5 changed files with 84 additions and 12 deletions

View File

@ -109,7 +109,7 @@ class User < ActiveRecord::Base
has_many :sidebar_section_links, dependent: :delete_all
has_many :category_sidebar_section_links, -> { where(linkable_type: "Category") }, class_name: 'SidebarSectionLink'
has_many :sidebar_tags, through: :sidebar_section_links, source: :linkable, source_type: "Tag"
has_many :custom_sidebar_tags, through: :sidebar_section_links, source: :linkable, source_type: "Tag"
delegate :last_sent_email_address, to: :email_logs
@ -1660,6 +1660,14 @@ class User < ActiveRecord::Base
Discourse.redis.del("#{REDESIGN_USER_MENU_REDIS_KEY_PREFIX}#{self.id}")
end
def sidebar_categories_ids
categories_ids = category_sidebar_section_links.pluck(:linkable_id)
if categories_ids.blank? && SiteSetting.default_sidebar_categories.present?
return guardian.allowed_category_ids & SiteSetting.default_sidebar_categories.split("|").map(&:to_i)
end
categories_ids
end
protected
def badge_grant
@ -1952,6 +1960,15 @@ class User < ActiveRecord::Base
end
end
def sidebar_tags
return custom_sidebar_tags if custom_sidebar_tags.present?
if SiteSetting.default_sidebar_tags.present?
tag_names = SiteSetting.default_sidebar_tags.split("|") - DiscourseTagging.hidden_tag_names(guardian)
return Tag.where(name: tag_names)
end
[]
end
def self.ensure_consistency!
DB.exec <<~SQL
UPDATE users