2020-01-26 13:08:47 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Entities
|
|
|
|
class User < UserBasic
|
2020-04-21 11:21:10 -04:00
|
|
|
include UsersHelper
|
2021-10-08 02:11:46 -04:00
|
|
|
include TimeZoneHelper
|
2021-09-06 11:10:54 -04:00
|
|
|
|
2020-01-26 13:08:47 -05:00
|
|
|
expose :created_at, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) }
|
2021-09-06 11:10:54 -04:00
|
|
|
expose :bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization, :job_title, :pronouns
|
2021-02-01 07:09:03 -05:00
|
|
|
expose :bot?, as: :bot
|
2020-04-21 11:21:10 -04:00
|
|
|
expose :work_information do |user|
|
|
|
|
work_information(user)
|
|
|
|
end
|
2021-02-15 16:08:59 -05:00
|
|
|
expose :followers, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) } do |user|
|
2021-03-29 08:09:14 -04:00
|
|
|
user.followers.size
|
2021-02-15 16:08:59 -05:00
|
|
|
end
|
|
|
|
expose :following, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) } do |user|
|
2021-03-29 08:09:14 -04:00
|
|
|
user.followees.size
|
2021-02-15 16:08:59 -05:00
|
|
|
end
|
2022-05-04 05:09:02 -04:00
|
|
|
expose :is_followed, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) && opts[:current_user] } do |user, opts|
|
|
|
|
opts[:current_user].following?(user)
|
|
|
|
end
|
2021-10-08 02:11:46 -04:00
|
|
|
expose :local_time do |user|
|
|
|
|
local_time(user.timezone)
|
|
|
|
end
|
2020-01-26 13:08:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|