diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 07:08:36 +0000 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /app/controllers/import | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) | |
download | gitlab-ce-48aff82709769b098321c738f3444b9bdaa694c6.tar.gz |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/available_namespaces_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/base_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/import/bulk_imports_controller.rb | 109 | ||||
-rw-r--r-- | app/controllers/import/fogbugz_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/github_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/gitlab_groups_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/import/manifest_controller.rb | 11 |
7 files changed, 123 insertions, 6 deletions
diff --git a/app/controllers/import/available_namespaces_controller.rb b/app/controllers/import/available_namespaces_controller.rb index 7983b4f20b5..c6211b33d28 100644 --- a/app/controllers/import/available_namespaces_controller.rb +++ b/app/controllers/import/available_namespaces_controller.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class Import::AvailableNamespacesController < ApplicationController + feature_category :importers + def index render json: NamespaceSerializer.new.represent(current_user.manageable_groups_with_routes) end diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb index 8a7a4c92b37..151ba46e629 100644 --- a/app/controllers/import/base_controller.rb +++ b/app/controllers/import/base_controller.rb @@ -4,6 +4,7 @@ class Import::BaseController < ApplicationController include ActionView::Helpers::SanitizeHelper before_action :import_rate_limit, only: [:create] + feature_category :importers def status respond_to do |format| diff --git a/app/controllers/import/bulk_imports_controller.rb b/app/controllers/import/bulk_imports_controller.rb new file mode 100644 index 00000000000..cb2922c2d47 --- /dev/null +++ b/app/controllers/import/bulk_imports_controller.rb @@ -0,0 +1,109 @@ +# frozen_string_literal: true + +class Import::BulkImportsController < ApplicationController + before_action :ensure_group_import_enabled + before_action :verify_blocked_uri, only: :status + + feature_category :importers + + rescue_from Gitlab::BulkImport::Client::ConnectionError, with: :bulk_import_connection_error + + def configure + session[access_token_key] = params[access_token_key]&.strip + session[url_key] = params[url_key] + + redirect_to status_import_bulk_import_url + end + + def status + respond_to do |format| + format.json do + render json: { importable_data: serialized_importable_data } + end + + format.html + end + end + + private + + def serialized_importable_data + serializer.represent(importable_data, {}, Import::BulkImportEntity) + end + + def serializer + @serializer ||= BaseSerializer.new(current_user: current_user) + end + + def importable_data + client.get('groups', top_level_only: true) + end + + def client + @client ||= Gitlab::BulkImport::Client.new( + uri: session[url_key], + token: session[access_token_key] + ) + end + + def import_params + params.permit(access_token_key, url_key) + end + + def ensure_group_import_enabled + render_404 unless Feature.enabled?(:bulk_import) + end + + def access_token_key + :bulk_import_gitlab_access_token + end + + def url_key + :bulk_import_gitlab_url + end + + def verify_blocked_uri + Gitlab::UrlBlocker.validate!( + session[url_key], + **{ + allow_localhost: allow_local_requests?, + allow_local_network: allow_local_requests?, + schemes: %w(http https) + } + ) + rescue Gitlab::UrlBlocker::BlockedUrlError => e + clear_session_data + + redirect_to new_group_path, alert: _('Specified URL cannot be used: "%{reason}"') % { reason: e.message } + end + + def allow_local_requests? + Gitlab::CurrentSettings.allow_local_requests_from_web_hooks_and_services? + end + + def bulk_import_connection_error(error) + clear_session_data + + error_message = _("Unable to connect to server: %{error}") % { error: error } + flash[:alert] = error_message + + respond_to do |format| + format.json do + render json: { + error: { + message: error_message, + redirect: new_group_path + } + }, status: :unprocessable_entity + end + format.html do + redirect_to new_group_path + end + end + end + + def clear_session_data + session[url_key] = nil + session[access_token_key] = nil + end +end diff --git a/app/controllers/import/fogbugz_controller.rb b/app/controllers/import/fogbugz_controller.rb index a34bc9c953f..bcbf5938e11 100644 --- a/app/controllers/import/fogbugz_controller.rb +++ b/app/controllers/import/fogbugz_controller.rb @@ -136,7 +136,7 @@ class Import::FogbugzController < Import::BaseController def verify_blocked_uri Gitlab::UrlBlocker.validate!( params[:uri], - { + **{ allow_localhost: allow_local_requests?, allow_local_network: allow_local_requests?, schemes: %w(http https) diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index 29fe34f0734..a1adc6e062a 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -108,7 +108,7 @@ class Import::GithubController < Import::BaseController @client ||= if Feature.enabled?(:remove_legacy_github_client) Gitlab::GithubImport::Client.new(session[access_token_key]) else - Gitlab::LegacyGithubImport::Client.new(session[access_token_key], client_options) + Gitlab::LegacyGithubImport::Client.new(session[access_token_key], **client_options) end end diff --git a/app/controllers/import/gitlab_groups_controller.rb b/app/controllers/import/gitlab_groups_controller.rb index 330af68385e..d8118477a80 100644 --- a/app/controllers/import/gitlab_groups_controller.rb +++ b/app/controllers/import/gitlab_groups_controller.rb @@ -6,6 +6,8 @@ class Import::GitlabGroupsController < ApplicationController before_action :ensure_group_import_enabled before_action :import_rate_limit, only: %i[create] + feature_category :importers + def create unless file_is_valid?(group_params[:file]) return redirect_back_or_default(options: { alert: s_('GroupImport|Unable to process group import file') }) diff --git a/app/controllers/import/manifest_controller.rb b/app/controllers/import/manifest_controller.rb index 9c47e6d4b0b..fdca6da95c5 100644 --- a/app/controllers/import/manifest_controller.rb +++ b/app/controllers/import/manifest_controller.rb @@ -26,8 +26,7 @@ class Import::ManifestController < Import::BaseController manifest = Gitlab::ManifestImport::Manifest.new(params[:manifest].tempfile) if manifest.valid? - session[:manifest_import_repositories] = manifest.projects - session[:manifest_import_group_id] = group.id + manifest_import_metadata.save(manifest.projects, group.id) redirect_to status_import_manifest_path else @@ -96,12 +95,16 @@ class Import::ManifestController < Import::BaseController # rubocop: disable CodeReuse/ActiveRecord def group - @group ||= Group.find_by(id: session[:manifest_import_group_id]) + @group ||= Group.find_by(id: manifest_import_metadata.group_id) end # rubocop: enable CodeReuse/ActiveRecord + def manifest_import_metadata + @manifest_import_status ||= Gitlab::ManifestImport::Metadata.new(current_user, fallback: session) + end + def repositories - @repositories ||= session[:manifest_import_repositories] + @repositories ||= manifest_import_metadata.repositories end def find_jobs |