summaryrefslogtreecommitdiff
path: root/lib/api/entities/user.rb
blob: 5c46233a639b452071aa45b08da89d79722abe3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module API
  module Entities
    class User < UserBasic
      include UsersHelper
      include ActionView::Helpers::SanitizeHelper

      expose :created_at, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) }
      expose :bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization, :job_title, :pronouns
      expose :bot?, as: :bot
      expose :work_information do |user|
        work_information(user)
      end
      expose :followers, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) } do |user|
        user.followers.size
      end
      expose :following, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) } do |user|
        user.followees.size
      end

      # This is only for multi version compatibility reasons, as we removed user.bio_html
      # to be removed in 14.4
      expose :bio_html do |user|
        strip_tags(user.bio)
      end
    end
  end
end