2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Import::GitlabGroupsController < ApplicationController
|
2021-02-22 17:27:13 +05:30
|
|
|
include WorkhorseAuthorization
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
before_action :check_import_rate_limit!, only: %i[create]
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :importers
|
2022-07-16 23:28:13 +05:30
|
|
|
urgency :low
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
def create
|
|
|
|
unless file_is_valid?(group_params[:file])
|
2021-04-17 20:07:23 +05:30
|
|
|
return redirect_to new_group_path(anchor: 'import-group-pane'), alert: s_('GroupImport|Unable to process group import file')
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
group_data = group_params.except(:file).merge(
|
|
|
|
visibility_level: closest_allowed_visibility_level,
|
|
|
|
import_export_upload: ImportExportUpload.new(import_file: group_params[:file])
|
|
|
|
)
|
|
|
|
|
|
|
|
group = ::Groups::CreateService.new(current_user, group_data).execute
|
|
|
|
|
|
|
|
if group.persisted?
|
|
|
|
if Groups::ImportExport::ImportService.new(group: group, user: current_user).async_execute
|
|
|
|
redirect_to(
|
|
|
|
group_path(group),
|
|
|
|
notice: s_("GroupImport|Group '%{group_name}' is being imported.") % { group_name: group.name }
|
|
|
|
)
|
|
|
|
else
|
|
|
|
redirect_to group_path(group), alert: _("Group import could not be scheduled")
|
|
|
|
end
|
|
|
|
else
|
2021-04-17 20:07:23 +05:30
|
|
|
redirect_to new_group_path(anchor: 'import-group-pane'),
|
|
|
|
alert: s_("GroupImport|Group could not be imported: %{errors}") % { errors: group.errors.full_messages.to_sentence }
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def group_params
|
|
|
|
params.permit(:path, :name, :parent_id, :file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def closest_allowed_visibility_level
|
|
|
|
if group_params[:parent_id].present?
|
|
|
|
parent_group = Group.find(group_params[:parent_id])
|
|
|
|
|
|
|
|
Gitlab::VisibilityLevel.closest_allowed_level(parent_group.visibility_level)
|
|
|
|
else
|
|
|
|
Gitlab::VisibilityLevel::PRIVATE
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
def check_import_rate_limit!
|
|
|
|
check_rate_limit!(:group_import, scope: current_user) do
|
|
|
|
redirect_to new_group_path, alert: _('This endpoint has been requested too many times. Try again later.')
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
def uploader_class
|
|
|
|
ImportExportUploader
|
|
|
|
end
|
|
|
|
|
|
|
|
def maximum_size
|
|
|
|
Gitlab::CurrentSettings.max_import_size.megabytes
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|