discourse/app/serializers/user_badge_serializer.rb

33 lines
750 B
Ruby
Raw Normal View History

2014-03-05 06:52:20 -06:00
class UserBadgeSerializer < ApplicationSerializer
class UserSerializer < BasicUserSerializer
attributes :name, :moderator, :admin
end
attributes :id, :granted_at, :count, :post_id, :post_number
2014-03-05 06:52:20 -06: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 02:22:42 -05:00
def include_count?
object.respond_to? :count
end
def include_post_id?
object.badge.show_posts && object.post_id && object.post
end
alias :include_topic? :include_post_id?
alias :include_post_number? :include_post_id?
def post_number
object.post && object.post.post_number
end
def topic
object.post.topic
end
2014-03-05 06:52:20 -06:00
end