mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 14:03:18 +08:00
FIX: Include permissions in the tag serializer (#27849)
The 'permissions' field is used by the composer and the category chooser to render the category.
This commit is contained in:
parent
d896f5cb70
commit
0e48f1aabe
|
@ -243,6 +243,18 @@ class Tag < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def all_category_ids
|
||||
@all_category_ids ||=
|
||||
categories.pluck(:id) +
|
||||
tag_groups.includes(:categories).flat_map { |tg| tg.categories.map(&:id) }
|
||||
end
|
||||
|
||||
def all_categories(guardian)
|
||||
categories = Category.secured(guardian).where(id: all_category_ids)
|
||||
Category.preload_user_fields!(guardian, categories)
|
||||
categories
|
||||
end
|
||||
|
||||
%i[tag_created tag_updated tag_destroyed].each do |event|
|
||||
define_method("trigger_#{event}_event") do
|
||||
DiscourseEvent.trigger(event, self)
|
||||
|
|
|
@ -10,11 +10,11 @@ class DetailedTagSerializer < TagSerializer
|
|||
end
|
||||
|
||||
def categories
|
||||
Category.secured(scope).where(id: category_ids)
|
||||
object.all_categories(scope)
|
||||
end
|
||||
|
||||
def category_restricted
|
||||
!category_ids.empty?
|
||||
object.all_category_ids.present?
|
||||
end
|
||||
|
||||
def include_tag_group_names?
|
||||
|
@ -24,12 +24,4 @@ class DetailedTagSerializer < TagSerializer
|
|||
def tag_group_names
|
||||
object.tag_groups.map(&:name)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def category_ids
|
||||
@_category_ids ||=
|
||||
object.categories.pluck(:id) +
|
||||
object.tag_groups.includes(:categories).map { |tg| tg.categories.map(&:id) }.flatten
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user