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>2023-03-22 21:15:17 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-22 21:15:17 +0300
commitde0e57e387034634a861555b878923cd077a039f (patch)
tree6532aac81d3e9e6bc6198a729bbd9bff5470fce3 /app/services/bulk_imports
parent8099b2824b5c3316af68fd8a5b9247c676a6d38b (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/bulk_imports')
-rw-r--r--app/services/bulk_imports/create_service.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/services/bulk_imports/create_service.rb b/app/services/bulk_imports/create_service.rb
index ac019d9ec5b..1db978bf1ec 100644
--- a/app/services/bulk_imports/create_service.rb
+++ b/app/services/bulk_imports/create_service.rb
@@ -27,6 +27,11 @@
#
module BulkImports
class CreateService
+ ENTITY_TYPES_MAPPING = {
+ 'group_entity' => 'groups',
+ 'project_entity' => 'projects'
+ }.freeze
+
attr_reader :current_user, :params, :credentials
def initialize(current_user, params, credentials)
@@ -57,6 +62,7 @@ module BulkImports
def validate!
client.validate_instance_version!
+ validate_setting_enabled!
client.validate_import_scopes!
end
@@ -88,6 +94,28 @@ module BulkImports
end
end
+ def validate_setting_enabled!
+ source_full_path, source_type = params[0].values_at(:source_full_path, :source_type)
+ entity_type = ENTITY_TYPES_MAPPING.fetch(source_type)
+ if source_full_path =~ /^[0-9]+$/
+ query = query_type(entity_type)
+ response = graphql_client.execute(
+ graphql_client.parse(query.to_s),
+ { full_path: source_full_path }
+ ).original_hash
+
+ source_entity_identifier = ::GlobalID.parse(response.dig(*query.data_path, 'id')).model_id
+ else
+ source_entity_identifier = ERB::Util.url_encode(source_full_path)
+ end
+
+ client.get("/#{entity_type}/#{source_entity_identifier}/export_relations/status")
+ # the source instance will return a 404 if the feature is disabled as the endpoint won't be available
+ rescue Gitlab::HTTP::BlockedUrlError
+ rescue BulkImports::NetworkError
+ raise ::BulkImports::Error.setting_not_enabled
+ end
+
def track_access_level(entity_params)
Gitlab::Tracking.event(
self.class.name,
@@ -140,5 +168,20 @@ module BulkImports
token: @credentials[:access_token]
)
end
+
+ def graphql_client
+ @graphql_client ||= BulkImports::Clients::Graphql.new(
+ url: @credentials[:url],
+ token: @credentials[:access_token]
+ )
+ end
+
+ def query_type(entity_type)
+ if entity_type == 'groups'
+ BulkImports::Groups::Graphql::GetGroupQuery.new(context: nil)
+ else
+ BulkImports::Projects::Graphql::GetProjectQuery.new(context: nil)
+ end
+ end
end
end