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 'lib/bulk_imports/groups')
-rw-r--r--lib/bulk_imports/groups/graphql/get_milestones_query.rb56
-rw-r--r--lib/bulk_imports/groups/loaders/group_loader.rb27
-rw-r--r--lib/bulk_imports/groups/pipelines/milestones_pipeline.rb15
-rw-r--r--lib/bulk_imports/groups/stage.rb2
4 files changed, 26 insertions, 74 deletions
diff --git a/lib/bulk_imports/groups/graphql/get_milestones_query.rb b/lib/bulk_imports/groups/graphql/get_milestones_query.rb
deleted file mode 100644
index 5dd5b31cf0e..00000000000
--- a/lib/bulk_imports/groups/graphql/get_milestones_query.rb
+++ /dev/null
@@ -1,56 +0,0 @@
-# frozen_string_literal: true
-
-module BulkImports
- module Groups
- module Graphql
- module GetMilestonesQuery
- extend self
-
- def to_s
- <<-'GRAPHQL'
- query ($full_path: ID!, $cursor: String, $per_page: Int) {
- group(fullPath: $full_path) {
- milestones(first: $per_page, after: $cursor, includeDescendants: false) {
- page_info: pageInfo {
- next_page: endCursor
- has_next_page: hasNextPage
- }
- nodes {
- iid
- title
- description
- state
- start_date: startDate
- due_date: dueDate
- created_at: createdAt
- updated_at: updatedAt
- }
- }
- }
- }
- GRAPHQL
- end
-
- def variables(context)
- {
- full_path: context.entity.source_full_path,
- cursor: context.tracker.next_page,
- per_page: ::BulkImports::Tracker::DEFAULT_PAGE_SIZE
- }
- end
-
- def base_path
- %w[data group milestones]
- end
-
- def data_path
- base_path << 'nodes'
- end
-
- def page_info_path
- base_path << 'page_info'
- end
- end
- end
- end
-end
diff --git a/lib/bulk_imports/groups/loaders/group_loader.rb b/lib/bulk_imports/groups/loaders/group_loader.rb
index a631685c2ad..5f5307123a5 100644
--- a/lib/bulk_imports/groups/loaders/group_loader.rb
+++ b/lib/bulk_imports/groups/loaders/group_loader.rb
@@ -4,10 +4,21 @@ module BulkImports
module Groups
module Loaders
class GroupLoader
+ GroupCreationError = Class.new(StandardError)
+
def load(context, data)
- return unless user_can_create_group?(context.current_user, data)
+ path = data['path']
+ current_user = context.current_user
+ destination_namespace = context.entity.destination_namespace
+
+ raise(GroupCreationError, 'Path is missing') unless path.present?
+ raise(GroupCreationError, 'Destination is not a group') if user_namespace_destination?(destination_namespace)
+ raise(GroupCreationError, 'User not allowed to create group') unless user_can_create_group?(current_user, data)
+ raise(GroupCreationError, 'Group exists') if group_exists?(destination_namespace, path)
+
+ group = ::Groups::CreateService.new(current_user, data).execute
- group = ::Groups::CreateService.new(context.current_user, data).execute
+ raise(GroupCreationError, group.errors.full_messages.to_sentence) if group.errors.any?
context.entity.update!(group: group)
@@ -25,6 +36,18 @@ module BulkImports
Ability.allowed?(current_user, :create_group)
end
end
+
+ def group_exists?(destination_namespace, path)
+ full_path = destination_namespace.present? ? File.join(destination_namespace, path) : path
+
+ Group.find_by_full_path(full_path).present?
+ end
+
+ def user_namespace_destination?(destination_namespace)
+ return false unless destination_namespace.present?
+
+ Namespace.find_by_full_path(destination_namespace)&.user_namespace?
+ end
end
end
end
diff --git a/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb b/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb
deleted file mode 100644
index b2bd14952e7..00000000000
--- a/lib/bulk_imports/groups/pipelines/milestones_pipeline.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-# frozen_string_literal: true
-
-module BulkImports
- module Groups
- module Pipelines
- class MilestonesPipeline
- include NdjsonPipeline
-
- relation_name 'milestones'
-
- extractor ::BulkImports::Common::Extractors::NdjsonExtractor, relation: relation
- end
- end
- end
-end
diff --git a/lib/bulk_imports/groups/stage.rb b/lib/bulk_imports/groups/stage.rb
index a1869b4cb0e..241dd428dd5 100644
--- a/lib/bulk_imports/groups/stage.rb
+++ b/lib/bulk_imports/groups/stage.rb
@@ -28,7 +28,7 @@ module BulkImports
stage: 1
},
milestones: {
- pipeline: BulkImports::Groups::Pipelines::MilestonesPipeline,
+ pipeline: BulkImports::Common::Pipelines::MilestonesPipeline,
stage: 1
},
badges: {