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:
Bianca Nenciu 2024-07-11 19:59:57 +03:00 committed by GitHub
parent d896f5cb70
commit 0e48f1aabe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 10 deletions

View File

@ -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)

View File

@ -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