discourse/app/serializers/user_badge_serializer.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

41 lines
858 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2014-03-05 20:52:20 +08:00
class UserBadgeSerializer < ApplicationSerializer
include UserBadgePostAndTopicAttributesMixin
class UserSerializer < BasicUserSerializer
include UserPrimaryGroupMixin
attributes :name, :moderator, :admin
end
attributes :id, :granted_at, :created_at, :count, :post_id, :post_number
2014-03-05 20:52:20 +08:00
has_one :badge
has_one :user, serializer: UserSerializer, root: :users
has_one :granted_by, serializer: UserSerializer, root: :users
has_one :topic, serializer: BasicTopicSerializer
2014-05-21 15:22:42 +08:00
def include_count?
object.respond_to? :count
end
def include_post_id?
include_post_attributes?
end
alias include_post_number? include_post_id?
def post_number
object.post && object.post.post_number
end
def topic
object.post.topic
end
def include_topic?
include_topic_attributes?
end
2014-03-05 20:52:20 +08:00
end