mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 05:43:38 +08:00
3e7601cada
It used to embed the objects which could lead to duplicated objects when the same user or category was used multiple times (user was admin, moderator and category or category was parent for multiple categories).
65 lines
1.5 KiB
Ruby
65 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class AboutSerializer < ApplicationSerializer
|
|
class CategoryAboutSerializer < CategoryBadgeSerializer
|
|
has_one :parent_category, serializer: CategoryBadgeSerializer, root: :categories
|
|
end
|
|
|
|
class UserAboutSerializer < BasicUserSerializer
|
|
attributes :title, :last_seen_at
|
|
end
|
|
|
|
class AboutCategoryModsSerializer < ApplicationSerializer
|
|
has_one :category, serializer: CategoryAboutSerializer
|
|
has_many :moderators, serializer: UserAboutSerializer, root: :users
|
|
end
|
|
|
|
has_many :moderators, serializer: UserAboutSerializer, root: :users
|
|
has_many :admins, serializer: UserAboutSerializer, root: :users
|
|
has_many :category_moderators, serializer: AboutCategoryModsSerializer, embed: :objects
|
|
|
|
attributes :stats,
|
|
:description,
|
|
:title,
|
|
:locale,
|
|
:version,
|
|
:https,
|
|
:can_see_about_stats,
|
|
:contact_url,
|
|
:contact_email
|
|
|
|
def include_stats?
|
|
can_see_about_stats
|
|
end
|
|
|
|
def stats
|
|
object.class.fetch_cached_stats
|
|
end
|
|
|
|
def include_contact_url?
|
|
can_see_site_contact_details
|
|
end
|
|
|
|
def contact_url
|
|
SiteSetting.contact_url
|
|
end
|
|
|
|
def include_contact_email?
|
|
can_see_site_contact_details
|
|
end
|
|
|
|
def contact_email
|
|
SiteSetting.contact_email
|
|
end
|
|
|
|
private
|
|
|
|
def can_see_about_stats
|
|
scope.can_see_about_stats?
|
|
end
|
|
|
|
def can_see_site_contact_details
|
|
scope.can_see_site_contact_details?
|
|
end
|
|
end
|