summaryrefslogtreecommitdiff
path: root/app/serializers/service_field_entity.rb
blob: 9929d7e2e5a5957f2cd4c9003389621c8acb98a2 (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
# frozen_string_literal: true

class ServiceFieldEntity < Grape::Entity
  include RequestAwareEntity

  expose :type, :name, :title, :placeholder, :required, :choices, :help

  expose :value do |field|
    # field[:name] is not user input and so can assume is safe
    value = service.public_send(field[:name]) # rubocop:disable GitlabSecurity/PublicSend

    if field[:type] == 'password' && value.present?
      'true'
    else
      value
    end
  end

  private

  def service
    request.service
  end
end