diff options
-rw-r--r-- | app/models/application_setting.rb | 12 | ||||
-rw-r--r-- | lib/api/entities.rb | 1 | ||||
-rw-r--r-- | lib/api/settings.rb | 2 | ||||
-rw-r--r-- | spec/models/application_setting_spec.rb | 6 |
4 files changed, 17 insertions, 4 deletions
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 17193036fb6..19af40eacb4 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -306,9 +306,15 @@ class ApplicationSetting < ActiveRecord::Base end def check_default_artifacts_expire_in - ChronicDuration.parse(default_artifacts_expire_in) if - default_artifacts_expire_in - true + return true unless default_artifacts_expire_in + + if ChronicDuration.parse(default_artifacts_expire_in).nil? + errors.add(:default_artifacts_expire_in, + "can't be 0. Leave it blank for unlimited") + false + else + true + end rescue ChronicDuration::DurationParseError => e errors.add(:default_artifacts_expire_in, ": #{e.message}") false diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 2a071e649fa..fb0584539db 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -559,6 +559,7 @@ module API expose :default_project_visibility expose :default_snippet_visibility expose :default_group_visibility + expose :default_artifacts_expire_in expose :domain_whitelist expose :domain_blacklist_enabled expose :domain_blacklist diff --git a/lib/api/settings.rb b/lib/api/settings.rb index f46e7e0bcf1..936c7e0930b 100644 --- a/lib/api/settings.rb +++ b/lib/api/settings.rb @@ -57,7 +57,7 @@ module API requires :shared_runners_text, type: String, desc: 'Shared runners text ' end optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts" - optional :default_artifacts_expire_in, type: Integer, desc: "Set the default expiration time for each job's artifacts" + optional :default_artifacts_expire_in, type: String, desc: "Set the default expiration time for each job's artifacts" optional :max_pages_size, type: Integer, desc: 'Maximum size of pages in MB' optional :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)' optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics' diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 15632bac094..9629f858609 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -36,6 +36,12 @@ describe ApplicationSetting, models: true do expect(setting).to be_invalid end + it 'does not allow 0' do + setting.update(default_artifacts_expire_in: '0') + + expect(setting).to be_invalid + end + it 'sets the value if it is valid' do setting.update(default_artifacts_expire_in: '30 days') |