2021-01-14 13:10:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class MemberUserEntity < UserEntity
|
|
|
|
unexpose :path
|
|
|
|
unexpose :state
|
|
|
|
unexpose :status_tooltip_html
|
|
|
|
|
2022-03-22 11:07:25 -04:00
|
|
|
expose :created_at
|
|
|
|
expose :last_activity_on
|
|
|
|
|
2021-01-14 13:10:59 -05:00
|
|
|
expose :avatar_url do |user|
|
|
|
|
user.avatar_url(size: Member::AVATAR_SIZE, only_path: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :blocked do |user|
|
|
|
|
user.blocked?
|
|
|
|
end
|
|
|
|
|
2022-06-30 17:09:49 -04:00
|
|
|
expose :two_factor_enabled, if: -> (user) { current_user_can_manage_members? || current_user?(user) } do |user|
|
2021-01-14 13:10:59 -05:00
|
|
|
user.two_factor_enabled?
|
|
|
|
end
|
|
|
|
|
|
|
|
expose :status, if: -> (user) { user.status.present? } do
|
|
|
|
expose :emoji do |user|
|
|
|
|
user.status.emoji
|
|
|
|
end
|
|
|
|
end
|
2022-06-30 17:09:49 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def current_user_can_manage_members?
|
|
|
|
return false unless options[:source]
|
|
|
|
|
|
|
|
Ability.allowed?(options[:current_user], :"admin_#{options[:source].to_ability_name}_member", options[:source])
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user?(user)
|
|
|
|
options[:current_user] == user
|
|
|
|
end
|
2021-01-14 13:10:59 -05:00
|
|
|
end
|
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
MemberUserEntity.prepend_mod_with('MemberUserEntity')
|