0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/app/serializers/admin_category_serializer.rb
Martin Brennan ec9adc7620
UX: Minor improvements for admin category management (#41754)
Followup d9dfa85e1b

Add action button to create new category, and link
to category discovery route from category badge

<img width="1109" height="658" alt="image"
src="https://github.com/user-attachments/assets/7152e5f3-78ed-4a5d-b9d0-167c4689d5ab"
/>
2026-07-16 13:20:26 +10:00

44 lines
960 B
Ruby
Vendored

# frozen_string_literal: true
class AdminCategorySerializer < ApplicationSerializer
attributes :id,
:slug,
:badge_chain,
:category_types,
:description_text,
:read_restricted,
:topic_count,
:edit_url
def badge_chain
ancestors
.push(object)
.map { |category| AdminCategoryBadgeSerializer.new(category, scope:, root: false).as_json }
end
def category_types
Categories::TypeRegistry
.all
.values
.select { |type| type.category_matches?(object) }
.map { |type| { id: type.type_id, name: type.metadata(guardian: scope)[:name] } }
end
def edit_url
"#{object.slug_url_without_id}/edit/general"
end
private
def ancestors
ancestors = []
parent = object.parent_category
while parent.present?
ancestors.unshift(parent)
parent = parent.parent_category
end
ancestors
end
end