diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index 17193036fb67d32251455ecb6c90bb08a4426193..19af40eacb4c9ac88ab30740a5dd35fbc9247c1f 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 2a071e649fa28908252e5ddcf87b478ab0025d65..fb0584539db763791db7c1eefe37f15cdcaf2b48 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 f46e7e0bcf15489178d37f57e59fa115b582a32b..936c7e0930b62c07bfda1311e19ff9f7bcfa883d 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 15632bac0947a2102c6f2f4219be1bf7a85f0522..9629f85860929efb2fb155d7c33a2b01f0bde995 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')