mirror of
https://github.com/discourse/discourse.git
synced 2025-06-28 15:55:40 +08:00
FEATURE: default sidebar categories and tags (#17939)
Ability to set up default sidebar categories and tags for authenticated users
This commit is contained in:

committed by
GitHub

parent
49fa2e93c2
commit
caab916569
@ -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
|
||||
|
Reference in New Issue
Block a user