2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-24 20:52:43 -05:00
|
|
|
class DetailedUserBadgeSerializer < BasicUserBadgeSerializer
|
2018-08-13 18:11:14 -04:00
|
|
|
has_one :granted_by, serializer: UserBadgeSerializer::UserSerializer
|
2015-02-24 20:52:43 -05:00
|
|
|
|
2021-06-01 04:33:40 -04:00
|
|
|
attributes :post_number, :topic_id, :topic_title, :is_favorite, :can_favorite
|
2015-02-24 20:52:43 -05:00
|
|
|
|
|
|
|
def include_post_number?
|
|
|
|
object.post
|
|
|
|
end
|
|
|
|
|
|
|
|
alias :include_topic_id? :include_post_number?
|
|
|
|
alias :include_topic_title? :include_post_number?
|
|
|
|
|
|
|
|
def post_number
|
|
|
|
object.post.post_number if object.post
|
|
|
|
end
|
|
|
|
|
|
|
|
def topic_id
|
|
|
|
object.post.topic_id if object.post
|
|
|
|
end
|
|
|
|
|
|
|
|
def topic_title
|
|
|
|
object.post.topic.title if object.post && object.post.topic
|
|
|
|
end
|
|
|
|
|
2021-06-01 04:33:40 -04:00
|
|
|
def can_favorite
|
2021-06-22 11:58:03 -04:00
|
|
|
SiteSetting.max_favorite_badges > 0 &&
|
2021-06-01 04:33:40 -04:00
|
|
|
(scope.current_user.present? && object.user_id == scope.current_user.id) &&
|
|
|
|
!(1..4).include?(object.badge_id)
|
|
|
|
end
|
2015-02-24 20:52:43 -05:00
|
|
|
end
|