Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/bulk_imports/entity.rb')
-rw-r--r--app/models/bulk_imports/entity.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/bulk_imports/entity.rb b/app/models/bulk_imports/entity.rb
index a4d0b7485ba..16224fde502 100644
--- a/app/models/bulk_imports/entity.rb
+++ b/app/models/bulk_imports/entity.rb
@@ -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