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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 12:09:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-28 12:09:06 +0300
commit7e8278c0f46cf6058efad5afd0aef177977bd663 (patch)
tree7ac46710921145bb782bcb208ea896e1548b168b /app/services/groups
parentbbf6581214128ae12a6ff32f66a0d03ee57a2e91 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/groups')
-rw-r--r--app/services/groups/import_export/import_service.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/services/groups/import_export/import_service.rb b/app/services/groups/import_export/import_service.rb
new file mode 100644
index 00000000000..628c8f5bac0
--- /dev/null
+++ b/app/services/groups/import_export/import_service.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+module Groups
+ module ImportExport
+ class ImportService
+ attr_reader :current_user, :group, :params
+
+ def initialize(group:, user:)
+ @group = group
+ @current_user = user
+ @shared = Gitlab::ImportExport::Shared.new(@group)
+ end
+
+ def execute
+ validate_user_permissions
+
+ if import_file && restorer.restore
+ @group
+ else
+ raise StandardError.new(@shared.errors.to_sentence)
+ end
+ rescue => e
+ raise StandardError.new(e.message)
+ ensure
+ remove_import_file
+ end
+
+ private
+
+ def import_file
+ @import_file ||= Gitlab::ImportExport::FileImporter.import(importable: @group,
+ archive_file: nil,
+ shared: @shared)
+ end
+
+ def restorer
+ @restorer ||= Gitlab::ImportExport::GroupTreeRestorer.new(user: @current_user,
+ shared: @shared,
+ group: @group,
+ group_hash: nil)
+ end
+
+ def remove_import_file
+ upload = @group.import_export_upload
+
+ return unless upload&.import_file&.file
+
+ upload.remove_import_file!
+ upload.save!
+ end
+
+ def validate_user_permissions
+ unless current_user.can?(:admin_group, group)
+ raise ::Gitlab::ImportExport::Error.new(
+ "User with ID: %s does not have permission to Group %s with ID: %s." %
+ [current_user.id, group.name, group.id])
+ end
+ end
+ end
+ end
+end