travis-api/lib/travis/api/app/endpoint/env_vars.rb
Piotr Sarnacki 6e5f225a1c Don't reset the value if a new value is provided
If a value is provided with a request to update the record, we should
not nullify it. We don't send decrypted private values to the client, so
if client provides it, it's probably pasted by the user.
2014-09-10 11:02:24 +02:00

32 lines
801 B
Ruby

require 'travis/api/app'
require 'travis/api/app/endpoint/setting_endpoint'
class Travis::Api::App
class Endpoint
class EnvVars < SettingsEndpoint
define_method(:name) { :env_vars }
define_routes!
def update
data = JSON.parse(request.body.read)[singular_name]
previously_public = record.public?
record.update(data)
# if we update from private to public reset value
if !previously_public && record.public? && data['value'].nil?
record.value = nil
end
if record.valid?
repo_settings.save
respond_with(record, type: singular_name, version: :v2)
else
status 422
respond_with(record, type: :validation_error, version: :v2)
end
end
end
end
end