debian-mirror-gitlab/app/serializers/member_user_entity.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
958 B
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
class MemberUserEntity < UserEntity
unexpose :path
unexpose :state
unexpose :status_tooltip_html
2022-06-21 17:19:12 +05:30
expose :created_at
expose :last_activity_on
2021-03-08 18:12:59 +05:30
expose :avatar_url do |user|
user.avatar_url(size: Member::AVATAR_SIZE, only_path: false)
end
expose :blocked do |user|
user.blocked?
end
2022-07-01 11:34:44 +05:30
expose :two_factor_enabled, if: -> (user) { current_user_can_manage_members? || current_user?(user) } do |user|
2021-03-08 18:12:59 +05:30
user.two_factor_enabled?
end
expose :status, if: -> (user) { user.status.present? } do
expose :emoji do |user|
user.status.emoji
end
end
2022-07-01 11:34:44 +05:30
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-03-08 18:12:59 +05:30
end
2021-06-08 01:23:25 +05:30
MemberUserEntity.prepend_mod_with('MemberUserEntity')