2018-09-23 15:44:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-02 05:16:24 -04:00
|
|
|
class Import::ManifestController < Import::BaseController
|
2020-08-18 20:10:34 -04:00
|
|
|
extend ::Gitlab::Utils::Override
|
|
|
|
|
2021-03-16 14:11:53 -04:00
|
|
|
before_action :disable_query_limiting, only: [:create]
|
2018-07-05 08:46:39 -04:00
|
|
|
before_action :verify_import_enabled
|
2018-07-05 08:24:53 -04:00
|
|
|
before_action :ensure_import_vars, only: [:create, :status]
|
2018-07-02 05:16:24 -04:00
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def status
|
2020-08-18 20:10:34 -04:00
|
|
|
super
|
2018-07-02 05:16:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def upload
|
|
|
|
group = Group.find(params[:group_id])
|
|
|
|
|
|
|
|
unless can?(current_user, :create_projects, group)
|
|
|
|
@errors = ["You don't have enough permissions to create projects in the selected group"]
|
|
|
|
|
2018-07-05 05:54:46 -04:00
|
|
|
render :new && return
|
2018-07-02 05:16:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
manifest = Gitlab::ManifestImport::Manifest.new(params[:manifest].tempfile)
|
|
|
|
|
|
|
|
if manifest.valid?
|
2020-09-25 05:09:40 -04:00
|
|
|
manifest_import_metadata.save(manifest.projects, group.id)
|
2018-07-02 05:16:24 -04:00
|
|
|
|
|
|
|
redirect_to status_import_manifest_path
|
|
|
|
else
|
|
|
|
@errors = manifest.errors
|
|
|
|
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-18 20:10:34 -04:00
|
|
|
def realtime_changes
|
|
|
|
super
|
2018-07-02 05:16:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2021-08-20 11:10:24 -04:00
|
|
|
repository = importable_repos.find do |project|
|
2018-07-02 05:16:24 -04:00
|
|
|
project[:id] == params[:repo_id].to_i
|
|
|
|
end
|
|
|
|
|
2018-07-06 09:21:22 -04:00
|
|
|
project = Gitlab::ManifestImport::ProjectCreator.new(repository, group, current_user).execute
|
2018-07-02 05:16:24 -04:00
|
|
|
|
|
|
|
if project.persisted?
|
2020-08-18 20:10:34 -04:00
|
|
|
render json: ProjectSerializer.new.represent(project, serializer: :import)
|
2018-07-02 05:16:24 -04:00
|
|
|
else
|
|
|
|
render json: { errors: project_save_error(project) }, status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-18 20:10:34 -04:00
|
|
|
protected
|
|
|
|
|
|
|
|
override :importable_repos
|
|
|
|
def importable_repos
|
2021-08-20 11:10:24 -04:00
|
|
|
@importable_repos ||= manifest_import_metadata.repositories
|
2020-08-18 20:10:34 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
override :incompatible_repos
|
|
|
|
def incompatible_repos
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
override :provider_name
|
|
|
|
def provider_name
|
|
|
|
:manifest
|
|
|
|
end
|
|
|
|
|
|
|
|
override :provider_url
|
|
|
|
def provider_url
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
override :extra_representation_opts
|
|
|
|
def extra_representation_opts
|
|
|
|
{ group_full_path: group.full_path }
|
|
|
|
end
|
|
|
|
|
2018-07-02 05:16:24 -04:00
|
|
|
private
|
|
|
|
|
2018-07-05 08:24:53 -04:00
|
|
|
def ensure_import_vars
|
2021-08-20 11:10:24 -04:00
|
|
|
unless group && importable_repos.present?
|
2018-07-02 05:16:24 -04:00
|
|
|
redirect_to(new_import_manifest_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2018-07-02 05:16:24 -04:00
|
|
|
def group
|
2020-09-25 05:09:40 -04:00
|
|
|
@group ||= Group.find_by(id: manifest_import_metadata.group_id)
|
2018-07-05 08:24:53 -04:00
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-07-05 08:24:53 -04:00
|
|
|
|
2020-09-25 05:09:40 -04:00
|
|
|
def manifest_import_metadata
|
|
|
|
@manifest_import_status ||= Gitlab::ManifestImport::Metadata.new(current_user, fallback: session)
|
|
|
|
end
|
|
|
|
|
2018-07-05 08:24:53 -04:00
|
|
|
def find_jobs
|
|
|
|
find_already_added_projects.to_json(only: [:id], methods: [:import_status])
|
|
|
|
end
|
|
|
|
|
2018-07-05 08:46:39 -04:00
|
|
|
def verify_import_enabled
|
|
|
|
render_404 unless manifest_import_enabled?
|
|
|
|
end
|
2018-07-06 08:06:44 -04:00
|
|
|
|
2021-03-16 14:11:53 -04:00
|
|
|
def disable_query_limiting
|
2021-03-24 23:09:35 -04:00
|
|
|
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/23147')
|
2018-07-06 08:06:44 -04:00
|
|
|
end
|
2018-07-02 05:16:24 -04:00
|
|
|
end
|