2020-04-07 11:58:49 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class InvitedSerializer < ApplicationSerializer
|
|
|
|
attributes :invites, :can_see_invite_details
|
|
|
|
|
|
|
|
def invites
|
2020-06-09 11:19:32 -04:00
|
|
|
serializer = if object.type == "pending"
|
|
|
|
InviteSerializer
|
|
|
|
else
|
|
|
|
InvitedUserSerializer
|
|
|
|
end
|
|
|
|
|
2020-04-07 11:58:49 -04:00
|
|
|
ActiveModel::ArraySerializer.new(
|
|
|
|
object.invite_list,
|
2020-06-09 11:19:32 -04:00
|
|
|
each_serializer: serializer,
|
2020-04-07 11:58:49 -04:00
|
|
|
scope: scope,
|
|
|
|
root: false,
|
|
|
|
show_emails: object.show_emails
|
|
|
|
).as_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_see_invite_details
|
|
|
|
scope.can_see_invite_details?(object.inviter)
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_attribute_for_serialization(attr)
|
|
|
|
object.respond_to?(attr) ? object.public_send(attr) : public_send(attr)
|
|
|
|
end
|
|
|
|
end
|