Commit 5578e46c authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'kassio/bulkimports-avoid-recursive-group-migration' into 'master'

BulkImports: avoid infinity recursion on group migration

See merge request gitlab-org/gitlab!52931
parents 7575f59a 0e58741c
......@@ -43,6 +43,8 @@ class BulkImports::Entity < ApplicationRecord
validate :validate_parent_is_a_group, if: :parent
validate :validate_imported_entity_type
validate :validate_destination_namespace_ascendency, if: :group_entity?
enum source_type: { group_entity: 0, project_entity: 1 }
state_machine :status, initial: :created do
......@@ -107,4 +109,17 @@ class BulkImports::Entity < ApplicationRecord
)
end
end
def validate_destination_namespace_ascendency
source = Group.find_by_full_path(source_full_path)
return unless source
if source.self_and_descendants.any? { |namespace| namespace.full_path == destination_namespace }
errors.add(
:destination_namespace,
s_('BulkImport|destination group cannot be part of the source group tree')
)
end
end
end
---
title: 'BulkImports: avoid infinity recursion on group migration'
merge_request: 52931
author:
type: fixed
......@@ -4926,6 +4926,9 @@ msgstr ""
msgid "BulkImport|Update of import statuses with realtime changes failed"
msgstr ""
msgid "BulkImport|destination group cannot be part of the source group tree"
msgstr ""
msgid "BulkImport|expected an associated Group but has an associated Project"
msgstr ""
......
......@@ -81,6 +81,37 @@ RSpec.describe BulkImports::Entity, type: :model do
expect(entity.errors).to include(:parent)
end
end
context 'validate destination namespace of a group_entity' do
it 'is invalid if destination namespace is the source namespace' do
group_a = create(:group, path: 'group_a')
entity = build(
:bulk_import_entity,
:group_entity,
source_full_path: group_a.full_path,
destination_namespace: group_a.full_path
)
expect(entity).not_to be_valid
expect(entity.errors).to include(:destination_namespace)
end
it 'is invalid if destination namespace is a descendant of the source' do
group_a = create(:group, path: 'group_a')
group_b = create(:group, parent: group_a, path: 'group_b')
entity = build(
:bulk_import_entity,
:group_entity,
source_full_path: group_a.full_path,
destination_namespace: group_b.full_path
)
expect(entity).not_to be_valid
expect(entity.errors).to include(:destination_namespace)
end
end
end
describe "#update_tracker_for" 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