2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-06 03:16:51 +08:00
|
|
|
class InviteSerializer < ApplicationSerializer
|
2021-03-03 17:45:29 +08:00
|
|
|
attributes :id,
|
2021-03-19 01:05:38 +08:00
|
|
|
:invite_key,
|
2021-03-03 17:45:29 +08:00
|
|
|
:link,
|
|
|
|
:email,
|
2021-12-08 23:06:57 +08:00
|
|
|
:domain,
|
2021-03-09 22:56:18 +08:00
|
|
|
:emailed,
|
2021-03-03 17:45:29 +08:00
|
|
|
:max_redemptions_allowed,
|
2021-03-12 00:19:32 +08:00
|
|
|
:redemption_count,
|
2021-03-03 17:45:29 +08:00
|
|
|
:custom_message,
|
2021-03-12 00:19:32 +08:00
|
|
|
:created_at,
|
2021-03-03 17:45:29 +08:00
|
|
|
:updated_at,
|
|
|
|
:expires_at,
|
2021-07-06 17:49:26 +08:00
|
|
|
:expired,
|
|
|
|
:warnings
|
2021-03-03 17:45:29 +08:00
|
|
|
|
|
|
|
has_many :topics, embed: :object, serializer: BasicTopicSerializer
|
|
|
|
has_many :groups, embed: :object, serializer: BasicGroupSerializer
|
2013-02-06 03:16:51 +08:00
|
|
|
|
|
|
|
def include_email?
|
2020-03-05 00:47:09 +08:00
|
|
|
options[:show_emails] && !object.redeemed?
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|
|
|
|
|
2021-03-09 22:56:18 +08:00
|
|
|
def include_emailed?
|
|
|
|
email.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def emailed
|
|
|
|
object.emailed_status != Invite.emailed_status_types[:not_required]
|
|
|
|
end
|
|
|
|
|
2021-03-12 00:19:32 +08:00
|
|
|
def include_custom_message?
|
|
|
|
email.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_max_redemptions_allowed?
|
|
|
|
email.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_redemption_count?
|
|
|
|
email.blank?
|
|
|
|
end
|
|
|
|
|
2014-01-22 04:13:55 +08:00
|
|
|
def expired
|
|
|
|
object.expired?
|
|
|
|
end
|
2021-07-06 17:49:26 +08:00
|
|
|
|
|
|
|
def warnings
|
|
|
|
object.warnings(scope)
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_warnings?
|
|
|
|
object.warnings(scope).present?
|
|
|
|
end
|
2013-02-06 03:16:51 +08:00
|
|
|
end
|