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