2020-06-03 05:08:47 -04:00
|
|
|
# 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'
|
2020-07-14 20:09:23 -04:00
|
|
|
elsif field[:type] == 'checkbox'
|
|
|
|
ActiveRecord::Type::Boolean.new.deserialize(value).to_s
|
2020-06-03 05:08:47 -04:00
|
|
|
else
|
|
|
|
value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def service
|
|
|
|
request.service
|
|
|
|
end
|
|
|
|
end
|