
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.
32 lines
801 B
Ruby
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
|