discourse/app/serializers/user_badge_serializer.rb
Sam 0f9678fe49 FIX: faster update of all badges
Introduced badge triggers, introduced concept of badge that happens due to a post but has the post hidden

Delta badge grant happens once a minute, backed by redis
2014-07-23 11:46:07 +10:00

27 lines
666 B
Ruby

class UserBadgeSerializer < ApplicationSerializer
attributes :id, :granted_at, :count, :post_id, :post_number
has_one :badge
has_one :user, serializer: BasicUserSerializer, root: :users
has_one :granted_by, serializer: BasicUserSerializer, root: :users
has_one :topic, serializer: BasicTopicSerializer
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
end