Commit 9b751925 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '219915-cleanup-policy-not-working' into 'master'

Update DeleteTagsService to allow policy to work

See merge request gitlab-org/gitlab!43359
parents 484c5964 a51fa7af
......@@ -25,7 +25,10 @@ module Projects
tag_names = tags.map(&:name)
Projects::ContainerRepository::DeleteTagsService
.new(container_repository.project, current_user, tags: tag_names)
.new(container_repository.project,
current_user,
tags: tag_names,
container_expiration_policy: params['container_expiration_policy'])
.execute(container_repository)
end
......
......@@ -7,7 +7,10 @@ module Projects
def execute(container_repository)
@container_repository = container_repository
unless params[:container_expiration_policy]
return error('access denied') unless can?(current_user, :destroy_container_image, project)
end
@tag_names = params[:tags]
return error('not tags specified') if @tag_names.blank?
......
---
title: Fix bug to allow container cleanup policies to properly run
merge_request: 43359
author:
type: fixed
......@@ -245,7 +245,7 @@ RSpec.describe Projects::ContainerRepository::CleanupTagsService do
end
it 'succeeds without a user' do
expect_delete(%w(Bb Ba C))
expect_delete(%w(Bb Ba C), container_expiration_policy: true)
is_expected.to include(status: :success, deleted: %w(Bb Ba C))
end
......@@ -287,10 +287,10 @@ RSpec.describe Projects::ContainerRepository::CleanupTagsService do
end
end
def expect_delete(tags)
def expect_delete(tags, container_expiration_policy: nil)
expect(Projects::ContainerRepository::DeleteTagsService)
.to receive(:new)
.with(repository.project, user, tags: tags)
.with(repository.project, user, tags: tags, container_expiration_policy: container_expiration_policy)
.and_call_original
expect_any_instance_of(Projects::ContainerRepository::DeleteTagsService)
......
......@@ -85,24 +85,7 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
end
end
describe '#execute' do
let(:tags) { %w[A Ba] }
subject { service.execute(repository) }
before do
stub_feature_flags(container_registry_expiration_policies_throttling: false)
end
context 'without permissions' do
it { is_expected.to include(status: :error) }
end
context 'with permissions' do
before do
project.add_developer(user)
end
RSpec.shared_examples 'supporting fast delete' do
context 'when the registry supports fast delete' do
before do
allow(repository.client).to receive(:supports_tag_delete?).and_return(true)
......@@ -135,6 +118,27 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
it_behaves_like 'logging an error response', message: 'timeout while deleting tags'
end
end
end
describe '#execute' do
let(:tags) { %w[A Ba] }
subject { service.execute(repository) }
before do
stub_feature_flags(container_registry_expiration_policies_throttling: false)
end
context 'without permissions' do
it { is_expected.to include(status: :error) }
end
context 'with permissions' do
before do
project.add_developer(user)
end
it_behaves_like 'supporting fast delete'
context 'when the registry does not support fast delete' do
before do
......@@ -146,5 +150,19 @@ RSpec.describe Projects::ContainerRepository::DeleteTagsService do
it_behaves_like 'handling invalid params'
end
end
context 'without user' do
let_it_be(:user) { nil }
context 'when not run by a cleanup policy' do
it { is_expected.to include(status: :error) }
end
context 'when run by a cleanup policy' do
let(:params) { { tags: tags, container_expiration_policy: true } }
it_behaves_like 'supporting fast delete'
end
end
end
end
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