2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class User < UserBasic
|
2020-04-22 19:07:51 +05:30
|
|
|
include UsersHelper
|
2021-11-18 22:05:49 +05:30
|
|
|
include TimeZoneHelper
|
2023-07-09 08:55:56 +05:30
|
|
|
include Gitlab::Utils::StrongMemoize
|
2021-11-11 11:23:49 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
expose :created_at, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) }
|
2023-04-23 21:23:45 +05:30
|
|
|
expose :bio, :location, :public_email, :skype, :linkedin, :twitter, :discord, :website_url, :organization, :job_title, :pronouns
|
2021-03-11 19:13:27 +05:30
|
|
|
expose :bot?, as: :bot
|
2020-04-22 19:07:51 +05:30
|
|
|
expose :work_information do |user|
|
|
|
|
work_information(user)
|
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
expose :followers, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) && following_users_allowed(opts[:current_user], user) } do |user|
|
2021-04-29 21:17:54 +05:30
|
|
|
user.followers.size
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
expose :following, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) && following_users_allowed(opts[:current_user], user) } do |user|
|
2021-04-29 21:17:54 +05:30
|
|
|
user.followees.size
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
expose :is_followed, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) && opts[:current_user] && following_users_allowed(opts[:current_user], user) } do |user, opts|
|
2022-08-13 15:12:31 +05:30
|
|
|
user.followed_by?(opts[:current_user])
|
2022-07-16 23:28:13 +05:30
|
|
|
end
|
2021-11-18 22:05:49 +05:30
|
|
|
expose :local_time do |user|
|
|
|
|
local_time(user.timezone)
|
2021-11-11 11:23:49 +05:30
|
|
|
end
|
2023-07-09 08:55:56 +05:30
|
|
|
|
|
|
|
def following_users_allowed(current_user, user)
|
|
|
|
strong_memoize(:following_users_allowed) do
|
|
|
|
if current_user
|
|
|
|
current_user.following_users_allowed?(user)
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|