Commit c62b9a16 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '349747-skip-delete-importing' into 'master'

Disallow tag deletion when container repository is importing

See merge request gitlab-org/gitlab!79660
parents d7cb5751 820ff2a8
...@@ -14,6 +14,7 @@ module Projects ...@@ -14,6 +14,7 @@ module Projects
@tag_names = params[:tags] @tag_names = params[:tags]
return error('not tags specified') if @tag_names.blank? return error('not tags specified') if @tag_names.blank?
return error('repository importing') if @container_repository.migration_importing?
delete_tags delete_tags
end end
......
...@@ -14,7 +14,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do ...@@ -14,7 +14,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
] ]
end end
RSpec.shared_examples 'logging a success response' do shared_examples 'logging a success response' do
it 'logs an info message' do it 'logs an info message' do
expect(service).to receive(:log_info).with( expect(service).to receive(:log_info).with(
service_class: 'Projects::ContainerRepository::DeleteTagsService', service_class: 'Projects::ContainerRepository::DeleteTagsService',
...@@ -28,7 +28,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do ...@@ -28,7 +28,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
end end
end end
RSpec.shared_examples 'logging an error response' do |message: 'could not delete tags', extra_log: {}| shared_examples 'logging an error response' do |message: 'could not delete tags', extra_log: {}|
it 'logs an error message' do it 'logs an error message' do
log_data = { log_data = {
service_class: 'Projects::ContainerRepository::DeleteTagsService', service_class: 'Projects::ContainerRepository::DeleteTagsService',
...@@ -45,7 +45,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do ...@@ -45,7 +45,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
end end
end end
RSpec.shared_examples 'calling the correct delete tags service' do |expected_service_class| shared_examples 'calling the correct delete tags service' do |expected_service_class|
let(:service_response) { { status: :success, deleted: tags } } let(:service_response) { { status: :success, deleted: tags } }
let(:excluded_service_class) { available_service_classes.excluding(expected_service_class).first } let(:excluded_service_class) { available_service_classes.excluding(expected_service_class).first }
...@@ -69,7 +69,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do ...@@ -69,7 +69,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
end end
end end
RSpec.shared_examples 'handling invalid params' do shared_examples 'handling invalid params' do
context 'with invalid params' do context 'with invalid params' do
before do before do
expect(::Projects::ContainerRepository::Gitlab::DeleteTagsService).not_to receive(:new) expect(::Projects::ContainerRepository::Gitlab::DeleteTagsService).not_to receive(:new)
...@@ -91,7 +91,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do ...@@ -91,7 +91,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
end end
end end
RSpec.shared_examples 'supporting fast delete' do shared_examples 'supporting fast delete' do
context 'when the registry supports fast delete' do context 'when the registry supports fast delete' do
before do before do
allow(repository.client).to receive(:supports_tag_delete?).and_return(true) allow(repository.client).to receive(:supports_tag_delete?).and_return(true)
...@@ -155,6 +155,14 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do ...@@ -155,6 +155,14 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
it_behaves_like 'handling invalid params' it_behaves_like 'handling invalid params'
end end
context 'when the repository is importing' do
before do
repository.update_columns(migration_state: 'importing', migration_import_started_at: Time.zone.now)
end
it { is_expected.to include(status: :error, message: 'repository importing') }
end
end end
context 'without user' do context 'without user' do
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
RSpec.shared_context 'container repository delete tags service shared context' do RSpec.shared_context 'container repository delete tags service shared context' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project, :private) } let_it_be(:project, reload: true) { create(:project, :private) }
let_it_be(:repository) { create(:container_repository, :root, project: project) } let_it_be_with_reload(:repository) { create(:container_repository, :root, project: project) }
let(:params) { { tags: tags } } let(:params) { { tags: tags } }
......
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