Commit bba99da9 authored by Stan Hu's avatar Stan Hu

Improve logging when username update fails due to registry tags

When a user cannot be renamed due to existing container registry tags, log the
namespace and an example project that has tags.
parent 2bb8c1ca
...@@ -5,8 +5,10 @@ module Storage ...@@ -5,8 +5,10 @@ module Storage
extend ActiveSupport::Concern extend ActiveSupport::Concern
def move_dir def move_dir
if any_project_has_container_registry_tags? proj_with_tags = first_project_with_container_registry_tags
raise Gitlab::UpdatePathError.new('Namespace cannot be moved, because at least one project has tags in container registry')
if proj_with_tags
raise Gitlab::UpdatePathError.new("Namespace #{name} (#{id}) cannot be moved because at least one project (e.g. #{proj_with_tags.name} (#{proj_with_tags.id})) has tags in container registry")
end end
parent_was = if parent_changed? && parent_id_was.present? parent_was = if parent_changed? && parent_id_was.present?
......
...@@ -135,6 +135,10 @@ class Namespace < ActiveRecord::Base ...@@ -135,6 +135,10 @@ class Namespace < ActiveRecord::Base
all_projects.any?(&:has_container_registry_tags?) all_projects.any?(&:has_container_registry_tags?)
end end
def first_project_with_container_registry_tags
all_projects.find(&:has_container_registry_tags?)
end
def send_update_instructions def send_update_instructions
projects.each do |project| projects.each do |project|
project.send_move_instructions("#{full_path_was}/#{project.path}") project.send_move_instructions("#{full_path_was}/#{project.path}")
......
---
title: Improve logging when username update fails due to registry tags
merge_request: 22038
author:
type: other
...@@ -82,6 +82,27 @@ describe Namespace do ...@@ -82,6 +82,27 @@ describe Namespace do
it { expect(namespace.human_name).to eq(namespace.owner_name) } it { expect(namespace.human_name).to eq(namespace.owner_name) }
end end
describe '#first_project_with_container_registry_tags' do
let(:container_repository) { create(:container_repository) }
let!(:project) { create(:project, namespace: namespace, container_repositories: [container_repository]) }
before do
stub_container_registry_config(enabled: true)
end
it 'returns the project' do
stub_container_registry_tags(repository: :any, tags: ['tag'])
expect(namespace.first_project_with_container_registry_tags).to eq(project)
end
it 'returns no project' do
stub_container_registry_tags(repository: :any, tags: nil)
expect(namespace.first_project_with_container_registry_tags).to be_nil
end
end
describe '.search' do describe '.search' do
let(:namespace) { create(:namespace) } let(:namespace) { create(:namespace) }
...@@ -184,7 +205,8 @@ describe Namespace do ...@@ -184,7 +205,8 @@ describe Namespace do
end end
it 'raises an error about not movable project' do it 'raises an error about not movable project' do
expect { namespace.move_dir }.to raise_error(/Namespace cannot be moved/) expect { namespace.move_dir }.to raise_error(Gitlab::UpdatePathError,
/Namespace .* cannot be moved/)
end end
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