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 'app/controllers/import')
-rw-r--r--app/controllers/import/bulk_imports_controller.rb17
-rw-r--r--app/controllers/import/fogbugz_controller.rb8
-rw-r--r--app/controllers/import/gitea_controller.rb8
-rw-r--r--app/controllers/import/github_controller.rb22
-rw-r--r--app/controllers/import/gitlab_groups_controller.rb10
-rw-r--r--app/controllers/import/gitlab_projects_controller.rb10
-rw-r--r--app/controllers/import/google_code_controller.rb123
7 files changed, 46 insertions, 152 deletions
diff --git a/app/controllers/import/bulk_imports_controller.rb b/app/controllers/import/bulk_imports_controller.rb
index 78f4a0cffca..4417cfe9098 100644
--- a/app/controllers/import/bulk_imports_controller.rb
+++ b/app/controllers/import/bulk_imports_controller.rb
@@ -20,8 +20,9 @@ class Import::BulkImportsController < ApplicationController
format.json do
render json: { importable_data: serialized_importable_data }
end
-
- format.html
+ format.html do
+ @source_url = session[url_key]
+ end
end
end
@@ -57,7 +58,7 @@ class Import::BulkImportsController < ApplicationController
end
def create_params
- params.permit(:bulk_import, [*bulk_import_params])
+ params.permit(bulk_import: bulk_import_params)[:bulk_import]
end
def bulk_import_params
@@ -84,11 +85,9 @@ class Import::BulkImportsController < ApplicationController
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)
- }
+ allow_localhost: allow_local_requests?,
+ allow_local_network: allow_local_requests?,
+ schemes: %w(http https)
)
rescue Gitlab::UrlBlocker::BlockedUrlError => e
clear_session_data
@@ -129,7 +128,7 @@ class Import::BulkImportsController < ApplicationController
def credentials
{
url: session[url_key],
- access_token: [access_token_key]
+ access_token: session[access_token_key]
}
end
end
diff --git a/app/controllers/import/fogbugz_controller.rb b/app/controllers/import/fogbugz_controller.rb
index bcbf5938e11..17f937a3dfd 100644
--- a/app/controllers/import/fogbugz_controller.rb
+++ b/app/controllers/import/fogbugz_controller.rb
@@ -136,11 +136,9 @@ 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)
- }
+ allow_localhost: allow_local_requests?,
+ allow_local_network: allow_local_requests?,
+ schemes: %w(http https)
)
rescue Gitlab::UrlBlocker::BlockedUrlError => e
redirect_to new_import_fogbugz_url, alert: _('Specified URL cannot be used: "%{reason}"') % { reason: e.message }
diff --git a/app/controllers/import/gitea_controller.rb b/app/controllers/import/gitea_controller.rb
index 4785a71b8a1..5a4eef352b8 100644
--- a/app/controllers/import/gitea_controller.rb
+++ b/app/controllers/import/gitea_controller.rb
@@ -72,11 +72,9 @@ class Import::GiteaController < Import::GithubController
def verify_blocked_uri
Gitlab::UrlBlocker.validate!(
provider_url,
- {
- allow_localhost: allow_local_requests?,
- allow_local_network: allow_local_requests?,
- schemes: %w(http https)
- }
+ allow_localhost: allow_local_requests?,
+ allow_local_network: allow_local_requests?,
+ schemes: %w(http https)
)
rescue Gitlab::UrlBlocker::BlockedUrlError => e
session[access_token_key] = nil
diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb
index 8ac93aeb9c0..beb3e92b5ea 100644
--- a/app/controllers/import/github_controller.rb
+++ b/app/controllers/import/github_controller.rb
@@ -17,6 +17,8 @@ class Import::GithubController < Import::BaseController
rescue_from Octokit::TooManyRequests, with: :provider_rate_limit
rescue_from Gitlab::GithubImport::RateLimitError, with: :rate_limit_threshold_exceeded
+ PAGE_LENGTH = 25
+
def new
if !ci_cd_only? && github_import_configured? && logged_in_with_provider?
go_to_provider_for_permissions
@@ -115,19 +117,16 @@ class Import::GithubController < Import::BaseController
def client_repos
@client_repos ||= if Feature.enabled?(:remove_legacy_github_client)
- concatenated_repos
+ if sanitized_filter_param
+ client.search_repos_by_name(sanitized_filter_param, pagination_options)[:items]
+ else
+ client.octokit.repos(nil, pagination_options)
+ end
else
filtered(client.repos)
end
end
- def concatenated_repos
- return [] unless client.respond_to?(:each_page)
- return client.each_page(:repos).flat_map(&:objects) unless sanitized_filter_param
-
- client.search_repos_by_name(sanitized_filter_param).flat_map(&:objects).flat_map(&:items)
- end
-
def sanitized_filter_param
super
@@ -257,6 +256,13 @@ class Import::GithubController < Import::BaseController
def rate_limit_threshold_exceeded
head :too_many_requests
end
+
+ def pagination_options
+ {
+ page: [1, params[:page].to_i].max,
+ per_page: PAGE_LENGTH
+ }
+ end
end
Import::GithubController.prepend_if_ee('EE::Import::GithubController')
diff --git a/app/controllers/import/gitlab_groups_controller.rb b/app/controllers/import/gitlab_groups_controller.rb
index d8118477a80..f68b76a7b36 100644
--- a/app/controllers/import/gitlab_groups_controller.rb
+++ b/app/controllers/import/gitlab_groups_controller.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Import::GitlabGroupsController < ApplicationController
- include WorkhorseImportExportUpload
+ include WorkhorseAuthorization
before_action :ensure_group_import_enabled
before_action :import_rate_limit, only: %i[create]
@@ -64,4 +64,12 @@ class Import::GitlabGroupsController < ApplicationController
redirect_to new_group_path
end
end
+
+ def uploader_class
+ ImportExportUploader
+ end
+
+ def maximum_size
+ Gitlab::CurrentSettings.max_import_size.megabytes
+ end
end
diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb
index 39d053347f0..0e6b0af6baf 100644
--- a/app/controllers/import/gitlab_projects_controller.rb
+++ b/app/controllers/import/gitlab_projects_controller.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
class Import::GitlabProjectsController < Import::BaseController
- include WorkhorseImportExportUpload
+ include WorkhorseAuthorization
before_action :whitelist_query_limiting, only: [:create]
before_action :verify_gitlab_project_import_enabled
@@ -45,4 +45,12 @@ class Import::GitlabProjectsController < Import::BaseController
def whitelist_query_limiting
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42437')
end
+
+ def uploader_class
+ ImportExportUploader
+ end
+
+ def maximum_size
+ Gitlab::CurrentSettings.max_import_size.megabytes
+ end
end
diff --git a/app/controllers/import/google_code_controller.rb b/app/controllers/import/google_code_controller.rb
deleted file mode 100644
index 03bde0345e3..00000000000
--- a/app/controllers/import/google_code_controller.rb
+++ /dev/null
@@ -1,123 +0,0 @@
-# frozen_string_literal: true
-
-class Import::GoogleCodeController < Import::BaseController
- before_action :verify_google_code_import_enabled
- before_action :user_map, only: [:new_user_map, :create_user_map]
-
- def new
- end
-
- def callback
- dump_file = params[:dump_file]
-
- unless dump_file.respond_to?(:read)
- return redirect_back_or_default(options: { alert: _("You need to upload a Google Takeout archive.") })
- end
-
- begin
- dump = Gitlab::Json.parse(dump_file.read)
- rescue
- return redirect_back_or_default(options: { alert: _("The uploaded file is not a valid Google Takeout archive.") })
- end
-
- client = Gitlab::GoogleCodeImport::Client.new(dump)
- unless client.valid?
- return redirect_back_or_default(options: { alert: _("The uploaded file is not a valid Google Takeout archive.") })
- end
-
- session[:google_code_dump] = dump
-
- if params[:create_user_map] == "1"
- redirect_to new_user_map_import_google_code_path
- else
- redirect_to status_import_google_code_path
- end
- end
-
- def new_user_map
- end
-
- def create_user_map
- user_map_json = params[:user_map]
- user_map_json = "{}" if user_map_json.blank?
-
- begin
- user_map = Gitlab::Json.parse(user_map_json)
- rescue
- flash.now[:alert] = _("The entered user map is not a valid JSON user map.")
-
- return render "new_user_map"
- end
-
- unless user_map.is_a?(Hash) && user_map.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
- flash.now[:alert] = _("The entered user map is not a valid JSON user map.")
-
- return render "new_user_map"
- end
-
- # This is the default, so let's not save it into the database.
- user_map.reject! do |key, value|
- value == Gitlab::GoogleCodeImport::Client.mask_email(key)
- end
-
- session[:google_code_user_map] = user_map
-
- flash[:notice] = _("The user map has been saved. Continue by selecting the projects you want to import.")
-
- redirect_to status_import_google_code_path
- end
-
- # rubocop: disable CodeReuse/ActiveRecord
- def status
- unless client.valid?
- return redirect_to new_import_google_code_path
- end
-
- @repos = client.repos
- @incompatible_repos = client.incompatible_repos
-
- @already_added_projects = find_already_added_projects('google_code')
- already_added_projects_names = @already_added_projects.pluck(:import_source)
-
- @repos.reject! { |repo| already_added_projects_names.include? repo.name }
- end
- # rubocop: enable CodeReuse/ActiveRecord
-
- def jobs
- render json: find_jobs('google_code')
- end
-
- def create
- repo = client.repo(params[:repo_id])
- user_map = session[:google_code_user_map]
-
- project = Gitlab::GoogleCodeImport::ProjectCreator.new(repo, current_user.namespace, current_user, user_map).execute
-
- if project.persisted?
- render json: ProjectSerializer.new.represent(project)
- else
- render json: { errors: project_save_error(project) }, status: :unprocessable_entity
- end
- end
-
- private
-
- def client
- @client ||= Gitlab::GoogleCodeImport::Client.new(session[:google_code_dump])
- end
-
- def verify_google_code_import_enabled
- render_404 unless google_code_import_enabled?
- end
-
- def user_map
- @user_map ||= begin
- user_map = client.user_map
-
- stored_user_map = session[:google_code_user_map]
- user_map.update(stored_user_map) if stored_user_map
-
- Hash[user_map.sort]
- end
- end
-end