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
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-24 00:09:31 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-24 00:09:31 +0300
commit427a082f7db22d4432f491aa7ee3a18a62a20d29 (patch)
tree6527fb894f736e6b7bb2c93f6ddedee4a4795b53 /lib
parentfdd0b0fd4592c74257980d07878db75705d22192 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/members.rb2
-rw-r--r--lib/gitlab/import_export.rb4
-rw-r--r--lib/gitlab/import_export/group/import_export.yml84
-rw-r--r--lib/gitlab/import_export/group/tree_saver.rb72
4 files changed, 162 insertions, 0 deletions
diff --git a/lib/api/members.rb b/lib/api/members.rb
index 2e49b4be45c..37d4ca29b68 100644
--- a/lib/api/members.rb
+++ b/lib/api/members.rb
@@ -160,3 +160,5 @@ module API
end
end
end
+
+API::Members.prepend_if_ee('EE::API::Members')
diff --git a/lib/gitlab/import_export.rb b/lib/gitlab/import_export.rb
index e696abcc51c..cb0a24c8864 100644
--- a/lib/gitlab/import_export.rb
+++ b/lib/gitlab/import_export.rb
@@ -91,6 +91,10 @@ module Gitlab
def legacy_group_config_file
Rails.root.join('lib/gitlab/import_export/group/legacy_import_export.yml')
end
+
+ def group_config_file
+ Rails.root.join('lib/gitlab/import_export/group/import_export.yml')
+ end
end
end
diff --git a/lib/gitlab/import_export/group/import_export.yml b/lib/gitlab/import_export/group/import_export.yml
new file mode 100644
index 00000000000..e30206dc509
--- /dev/null
+++ b/lib/gitlab/import_export/group/import_export.yml
@@ -0,0 +1,84 @@
+# Model relationships to be included in the group import/export
+#
+# This list _must_ only contain relationships that are available to both FOSS and
+# Enterprise editions. EE specific relationships must be defined in the `ee` section further
+# down below.
+tree:
+ group:
+ - :milestones
+ - :badges
+ - labels:
+ - :priorities
+ - boards:
+ - lists:
+ - label:
+ - :priorities
+ - :board
+ - members:
+ - :user
+
+included_attributes:
+ user:
+ - :id
+ - :email
+ - :username
+ author:
+ - :name
+
+excluded_attributes:
+ group:
+ - :owner_id
+ - :created_at
+ - :updated_at
+ - :runners_token
+ - :runners_token_encrypted
+ - :saml_discovery_token
+ - :visibility_level
+ - :trial_ends_on
+ - :shared_runners_minute_limit
+ - :extra_shared_runners_minutes_limit
+ epics:
+ - :state_id
+
+methods:
+ labels:
+ - :type
+ label:
+ - :type
+ badges:
+ - :type
+ notes:
+ - :type
+ events:
+ - :action
+ lists:
+ - :list_type
+ epics:
+ - :state
+
+preloads:
+
+# EE specific relationships and settings to include. All of this will be merged
+# into the previous structures if EE is used.
+ee:
+ tree:
+ group:
+ - epics:
+ - :parent
+ - :award_emoji
+ - events:
+ - :push_event_payload
+ - notes:
+ - :author
+ - :award_emoji
+ - events:
+ - :push_event_payload
+ - boards:
+ - :board_assignee
+ - :milestone
+ - labels:
+ - :priorities
+ - lists:
+ - milestone:
+ - events:
+ - :push_event_payload
diff --git a/lib/gitlab/import_export/group/tree_saver.rb b/lib/gitlab/import_export/group/tree_saver.rb
new file mode 100644
index 00000000000..d538de33c51
--- /dev/null
+++ b/lib/gitlab/import_export/group/tree_saver.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module ImportExport
+ module Group
+ class TreeSaver
+ attr_reader :full_path, :shared
+
+ def initialize(group:, current_user:, shared:, params: {})
+ @params = params
+ @current_user = current_user
+ @shared = shared
+ @group = group
+ @full_path = File.join(@shared.export_path, 'tree')
+ end
+
+ def save
+ all_groups = Enumerator.new do |group_ids|
+ groups.each do |group|
+ serialize(group)
+ group_ids << group.id
+ end
+ end
+
+ json_writer.write_relation_array('groups', '_all', all_groups)
+
+ true
+ rescue => e
+ @shared.error(e)
+ false
+ ensure
+ json_writer&.close
+ end
+
+ private
+
+ def groups
+ @groups ||= Gitlab::ObjectHierarchy
+ .new(::Group.where(id: @group.id))
+ .base_and_descendants(with_depth: true)
+ .order_by(:depth)
+ end
+
+ def serialize(group)
+ ImportExport::JSON::StreamingSerializer.new(
+ group,
+ group_tree,
+ json_writer,
+ exportable_path: "groups/#{group.id}"
+ ).execute
+ end
+
+ def group_tree
+ @group_tree ||= Gitlab::ImportExport::Reader.new(
+ shared: @shared,
+ config: group_config
+ ).group_tree
+ end
+
+ def group_config
+ Gitlab::ImportExport::Config.new(
+ config: Gitlab::ImportExport.group_config_file
+ ).to_h
+ end
+
+ def json_writer
+ @json_writer ||= ImportExport::JSON::NdjsonWriter.new(@full_path)
+ end
+ end
+ end
+ end
+end