discourse/app/serializers/user_badge_serializer.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

39 lines
846 B
Ruby

# frozen_string_literal: true
class UserBadgeSerializer < ApplicationSerializer
class UserSerializer < BasicUserSerializer
include UserPrimaryGroupMixin
attributes :name,
:moderator,
:admin
end
attributes :id, :granted_at, :count, :post_id, :post_number
has_one :badge
has_one :user, serializer: UserSerializer, root: :users
has_one :granted_by, serializer: UserSerializer, 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