Commit 2c352f9d authored by Matija Čupić's avatar Matija Čupić Committed by Imre Farkas

Add helper for expired locked artifacts

Add method for checking if build has expired locked artifacts archive.
parent 5497fa47
...@@ -782,6 +782,11 @@ module Ci ...@@ -782,6 +782,11 @@ module Ci
end end
end end
def has_expired_locked_archive_artifacts?
locked_artifacts? &&
artifacts_expire_at.present? && artifacts_expire_at < Time.current
end
def has_expiring_archive_artifacts? def has_expiring_archive_artifacts?
has_expiring_artifacts? && job_artifacts_archive.present? has_expiring_artifacts? && job_artifacts_archive.present?
end end
......
...@@ -35,7 +35,7 @@ class BuildDetailsEntity < JobEntity ...@@ -35,7 +35,7 @@ class BuildDetailsEntity < JobEntity
browse_project_job_artifacts_path(project, build) browse_project_job_artifacts_path(project, build)
end end
expose :keep_path, if: -> (*) { (build.locked_artifacts? || build.has_expiring_archive_artifacts?) && can?(current_user, :update_build, build) } do |build| expose :keep_path, if: -> (*) { (build.has_expired_locked_archive_artifacts? || build.has_expiring_archive_artifacts?) && can?(current_user, :update_build, build) } do |build|
keep_project_job_artifacts_path(project, build) keep_project_job_artifacts_path(project, build)
end end
......
---
title: Show keep path for expired locked artifacts.
merge_request: 43866
author:
type: changed
...@@ -197,16 +197,40 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do ...@@ -197,16 +197,40 @@ RSpec.describe Projects::JobsController, :clean_gitlab_redis_shared_state do
context 'with not expiry date' do context 'with not expiry date' do
let(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline) } let(:job) { create(:ci_build, :success, :artifacts, pipeline: pipeline) }
it 'exposes needed information' do context 'when artifacts are unlocked' do
get_show_json before do
job.pipeline.unlocked!
end
expect(response).to have_gitlab_http_status(:ok) it 'exposes needed information' do
expect(response).to match_response_schema('job/job_details') get_show_json
expect(json_response['artifact']['download_path']).to match(%r{artifacts/download})
expect(json_response['artifact']['browse_path']).to match(%r{artifacts/browse}) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['artifact']).not_to have_key('keep_path') expect(response).to match_response_schema('job/job_details')
expect(json_response['artifact']).not_to have_key('expired') expect(json_response['artifact']['download_path']).to match(%r{artifacts/download})
expect(json_response['artifact']).not_to have_key('expired_at') expect(json_response['artifact']['browse_path']).to match(%r{artifacts/browse})
expect(json_response['artifact']).not_to have_key('keep_path')
expect(json_response['artifact']).not_to have_key('expired')
expect(json_response['artifact']).not_to have_key('expired_at')
end
end
context 'when artifacts are locked' do
before do
job.pipeline.artifacts_locked!
end
it 'exposes needed information' do
get_show_json
expect(response).to have_gitlab_http_status(:ok)
expect(response).to match_response_schema('job/job_details')
expect(json_response['artifact']['download_path']).to match(%r{artifacts/download})
expect(json_response['artifact']['browse_path']).to match(%r{artifacts/browse})
expect(json_response['artifact']).not_to have_key('keep_path')
expect(json_response['artifact']).not_to have_key('expired')
expect(json_response['artifact']).not_to have_key('expired_at')
end
end end
end end
......
...@@ -2305,6 +2305,54 @@ RSpec.describe Ci::Build do ...@@ -2305,6 +2305,54 @@ RSpec.describe Ci::Build do
end end
end end
describe '#has_expired_locked_archive_artifacts?' do
subject { build.has_expired_locked_archive_artifacts? }
context 'when build does not have artifacts' do
it { is_expected.to eq(nil) }
end
context 'when build has artifacts' do
before do
create(:ci_job_artifact, :archive, job: build)
end
context 'when artifacts are unlocked' do
before do
build.pipeline.unlocked!
end
it { is_expected.to eq(false) }
end
context 'when artifacts are locked' do
before do
build.pipeline.artifacts_locked!
end
context 'when artifacts do not expire' do
it { is_expected.to eq(false) }
end
context 'when artifacts expire in the future' do
before do
build.update!(artifacts_expire_at: 1.day.from_now)
end
it { is_expected.to eq(false) }
end
context 'when artifacts expired in the past' do
before do
build.update!(artifacts_expire_at: 1.day.ago)
end
it { is_expected.to eq(true) }
end
end
end
end
describe '#has_expiring_archive_artifacts?' do describe '#has_expiring_archive_artifacts?' do
context 'when artifacts have expiration date set' do context 'when artifacts have expiration date set' do
before do before do
......
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