Commit 53c94f9e authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent ac872078
...@@ -83,7 +83,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -83,7 +83,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:akismet_api_key, :akismet_api_key,
:akismet_enabled, :akismet_enabled,
:container_registry_token_expire_delay, :container_registry_token_expire_delay,
:default_artifacts_expiration, :default_artifacts_expire_in,
:default_branch_protection, :default_branch_protection,
:default_group_visibility, :default_group_visibility,
:default_project_visibility, :default_project_visibility,
......
...@@ -80,9 +80,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -80,9 +80,7 @@ class ApplicationSetting < ActiveRecord::Base
presence: true, presence: true,
numericality: { only_integer: true, greater_than: 0 } numericality: { only_integer: true, greater_than: 0 }
validates :default_artifacts_expiration, validate :check_default_artifacts_expire_in
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :container_registry_token_expire_delay, validates :container_registry_token_expire_delay,
presence: true, presence: true,
...@@ -176,7 +174,7 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -176,7 +174,7 @@ class ApplicationSetting < ActiveRecord::Base
after_sign_up_text: nil, after_sign_up_text: nil,
akismet_enabled: false, akismet_enabled: false,
container_registry_token_expire_delay: 5, container_registry_token_expire_delay: 5,
default_artifacts_expiration: 30, default_artifacts_expire_in: '30 days',
default_branch_protection: Settings.gitlab['default_branch_protection'], default_branch_protection: Settings.gitlab['default_branch_protection'],
default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'], default_project_visibility: Settings.gitlab.default_projects_features['visibility_level'],
default_projects_limit: Settings.gitlab['default_projects_limit'], default_projects_limit: Settings.gitlab['default_projects_limit'],
...@@ -291,12 +289,6 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -291,12 +289,6 @@ class ApplicationSetting < ActiveRecord::Base
sidekiq_throttling_enabled sidekiq_throttling_enabled
end end
def default_artifacts_expire_in
if default_artifacts_expiration.nonzero?
"#{default_artifacts_expiration} days"
end
end
private private
def check_repository_storages def check_repository_storages
...@@ -304,4 +296,12 @@ class ApplicationSetting < ActiveRecord::Base ...@@ -304,4 +296,12 @@ class ApplicationSetting < ActiveRecord::Base
errors.add(:repository_storages, "can't include: #{invalid.join(", ")}") unless errors.add(:repository_storages, "can't include: #{invalid.join(", ")}") unless
invalid.empty? invalid.empty?
end end
def check_default_artifacts_expire_in
ChronicDuration.parse(default_artifacts_expire_in)
true
rescue ChronicDuration::DurationParseError => e
errors.add(:default_artifacts_expire_in, ": #{e.message}")
false
end
end end
...@@ -513,18 +513,6 @@ module Ci ...@@ -513,18 +513,6 @@ module Ci
end end
end end
def set_artifacts_expire_in(expire_in)
value =
if expire_in
expire_in
else
Gitlab::CurrentSettings.current_application_settings
.default_artifacts_expire_in
end
self.artifacts_expire_in = value
end
def has_expiring_artifacts? def has_expiring_artifacts?
artifacts_expire_at.present? artifacts_expire_at.present?
end end
......
...@@ -213,14 +213,14 @@ ...@@ -213,14 +213,14 @@
= f.number_field :max_artifacts_size, class: 'form-control' = f.number_field :max_artifacts_size, class: 'form-control'
.help-block .help-block
Set the maximum file size for each job's artifacts Set the maximum file size for each job's artifacts
= link_to "(?)", help_page_path("user/admin_area/settings/continuous_integration", anchor: "maximum-artifacts-size") = link_to icon('question-circle'), help_page_path('user/admin_area/settings/continuous_integration', anchor: 'maximum-artifacts-size')
.form-group .form-group
= f.label :default_artifacts_expiration, 'Default artifacts expiration (days)', class: 'control-label col-sm-2' = f.label :default_artifacts_expire_in, 'Default artifacts expiration', class: 'control-label col-sm-2'
.col-sm-10 .col-sm-10
= f.number_field :default_artifacts_expiration, class: 'form-control' = f.text_field :default_artifacts_expire_in, class: 'form-control'
.help-block .help-block
Set the default expiration time for each job's artifacts (0 as never expired) Set the default expiration time for each job's artifacts
= link_to "(?)", help_page_path("user/admin_area/settings/continuous_integration", anchor: "default-artifacts-expiration") = link_to icon('question-circle'), help_page_path('user/admin_area/settings/continuous_integration', anchor: 'default-artifacts-expiration')
- if Gitlab.config.registry.enabled - if Gitlab.config.registry.enabled
%fieldset %fieldset
......
...@@ -5,7 +5,7 @@ class AddDefaultArtifactsExpirationToApplicationSettings < ActiveRecord::Migrati ...@@ -5,7 +5,7 @@ class AddDefaultArtifactsExpirationToApplicationSettings < ActiveRecord::Migrati
def change def change
add_column :application_settings, add_column :application_settings,
:default_artifacts_expiration, :default_artifacts_expire_in,
:integer, default: 0, null: false :string, null: true
end end
end end
...@@ -57,7 +57,7 @@ module API ...@@ -57,7 +57,7 @@ module API
requires :shared_runners_text, type: String, desc: 'Shared runners text ' requires :shared_runners_text, type: String, desc: 'Shared runners text '
end end
optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts" optional :max_artifacts_size, type: Integer, desc: "Set the maximum file size for each job's artifacts"
optional :default_artifacts_expiration, type: Integer, desc: "Set the default expiration time for each job's artifacts" optional :default_artifacts_expire_in, type: Integer, 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 :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 :container_registry_token_expire_delay, type: Integer, desc: 'Authorization token duration (minutes)'
optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics' optional :metrics_enabled, type: Boolean, desc: 'Enable the InfluxDB metrics'
...@@ -119,7 +119,7 @@ module API ...@@ -119,7 +119,7 @@ module API
:after_sign_up_text, :signin_enabled, :require_two_factor_authentication, :after_sign_up_text, :signin_enabled, :require_two_factor_authentication,
:home_page_url, :after_sign_out_path, :sign_in_text, :help_page_text, :home_page_url, :after_sign_out_path, :sign_in_text, :help_page_text,
:shared_runners_enabled, :max_artifacts_size, :shared_runners_enabled, :max_artifacts_size,
:default_artifacts_expiration, :max_pages_size, :default_artifacts_expire_in, :max_pages_size,
:container_registry_token_expire_delay, :container_registry_token_expire_delay,
:metrics_enabled, :sidekiq_throttling_enabled, :recaptcha_enabled, :metrics_enabled, :sidekiq_throttling_enabled, :recaptcha_enabled,
:akismet_enabled, :admin_notification_email, :sentry_enabled, :akismet_enabled, :admin_notification_email, :sentry_enabled,
......
...@@ -167,7 +167,10 @@ module Ci ...@@ -167,7 +167,10 @@ module Ci
build.artifacts_file = artifacts build.artifacts_file = artifacts
build.artifacts_metadata = metadata build.artifacts_metadata = metadata
build.set_artifacts_expire_in(params['expire_in']) build.artifacts_expire_in =
params['expire_in'] ||
Gitlab::CurrentSettings.current_application_settings
.default_artifacts_expire_in
if build.save if build.save
present(build, with: Entities::BuildDetails) present(build, with: Entities::BuildDetails)
......
...@@ -630,7 +630,7 @@ describe Ci::API::Builds do ...@@ -630,7 +630,7 @@ describe Ci::API::Builds do
context 'with an expire date' do context 'with an expire date' do
let!(:artifacts) { file_upload } let!(:artifacts) { file_upload }
let(:default_artifacts_expiration) { 0 } let(:default_artifacts_expire_in) {}
let(:post_data) do let(:post_data) do
{ 'file.path' => artifacts.path, { 'file.path' => artifacts.path,
...@@ -640,7 +640,7 @@ describe Ci::API::Builds do ...@@ -640,7 +640,7 @@ describe Ci::API::Builds do
before do before do
stub_application_setting( stub_application_setting(
default_artifacts_expiration: default_artifacts_expiration) default_artifacts_expire_in: default_artifacts_expire_in)
post(post_url, post_data, headers_with_token) post(post_url, post_data, headers_with_token)
end end
...@@ -668,7 +668,7 @@ describe Ci::API::Builds do ...@@ -668,7 +668,7 @@ describe Ci::API::Builds do
end end
context 'with application default' do context 'with application default' do
let(:default_artifacts_expiration) { 5 } let(:default_artifacts_expire_in) { '5 days' }
it 'sets to application default' do it 'sets to application default' do
build.reload build.reload
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment