2021-01-14 13:10:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class MemberEntity < Grape::Entity
|
|
|
|
include RequestAwareEntity
|
|
|
|
include AvatarsHelper
|
|
|
|
|
|
|
|
expose :id
|
|
|
|
expose :created_at
|
|
|
|
expose :expires_at do |member|
|
|
|
|
member.expires_at&.to_time
|
|
|
|
end
|
|
|
|
expose :requested_at
|
|
|
|
|
|
|
|
expose :created_by, if: -> (member) { member.created_by.present? } do |member|
|
|
|
|
UserEntity.represent(member.created_by, only: [:name, :web_url])
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_update do |member|
|
|
|
|
member.can_update?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_remove do |member|
|
|
|
|
member.can_remove?
|
|
|
|
end
|
|
|
|
|
2021-01-28 13:09:27 -05:00
|
|
|
expose :is_direct_member do |member, options|
|
|
|
|
member.source == options[:source]
|
|
|
|
end
|
|
|
|
|
2021-01-14 13:10:59 -05:00
|
|
|
expose :access_level do
|
|
|
|
expose :human_access, as: :string_value
|
|
|
|
expose :access_level, as: :integer_value
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :source do |member|
|
|
|
|
GroupEntity.represent(member.source, only: [:id, :full_name, :web_url])
|
|
|
|
end
|
|
|
|
|
2021-03-23 08:09:33 -04:00
|
|
|
expose :type
|
|
|
|
|
2021-01-14 13:10:59 -05:00
|
|
|
expose :valid_level_roles, as: :valid_roles
|
|
|
|
|
2021-06-01 17:10:06 -04:00
|
|
|
expose :user, if: -> (member) { member.user.present? } do |member, options|
|
|
|
|
MemberUserEntity.represent(member.user, source: options[:source])
|
|
|
|
end
|
2021-01-14 13:10:59 -05:00
|
|
|
|
2021-10-13 08:12:20 -04:00
|
|
|
expose :state
|
|
|
|
|
2021-01-14 13:10:59 -05:00
|
|
|
expose :invite, if: -> (member) { member.invite? } do
|
|
|
|
expose :email do |member|
|
|
|
|
member.invite_email
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :avatar_url do |member|
|
|
|
|
avatar_icon_for_email(member.invite_email, Member::AVATAR_SIZE)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :can_resend do |member|
|
|
|
|
member.can_resend_invite?
|
|
|
|
end
|
2021-10-13 08:12:20 -04:00
|
|
|
|
|
|
|
expose :user_state do |member|
|
|
|
|
member.respond_to?(:invited_user_state) ? member.invited_user_state : ""
|
|
|
|
end
|
2021-01-14 13:10:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
MemberEntity.prepend_mod_with('MemberEntity')
|