2016-04-26 04:59:00 -04:00
|
|
|
class Import::GitlabProjectsController < Import::BaseController
|
2016-04-25 12:00:15 -04:00
|
|
|
before_action :verify_gitlab_project_import_enabled
|
2016-08-11 10:59:37 -04:00
|
|
|
before_action :authenticate_admin!
|
2016-04-25 12:00:15 -04:00
|
|
|
|
2016-04-26 04:59:00 -04:00
|
|
|
def new
|
2016-04-26 11:12:50 -04:00
|
|
|
@namespace_id = project_params[:namespace_id]
|
2016-06-15 11:31:00 -04:00
|
|
|
@namespace_name = Namespace.find(project_params[:namespace_id]).name
|
2016-04-26 11:12:50 -04:00
|
|
|
@path = project_params[:path]
|
2016-04-25 12:00:15 -04:00
|
|
|
end
|
|
|
|
|
2016-05-13 11:03:03 -04:00
|
|
|
def create
|
2016-06-13 14:35:57 -04:00
|
|
|
unless file_is_valid?
|
|
|
|
return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
|
|
|
|
end
|
|
|
|
|
2016-08-02 05:32:28 -04:00
|
|
|
import_upload_path = Gitlab::ImportExport.import_upload_path(filename: project_params[:file].original_filename)
|
2016-06-24 04:50:23 -04:00
|
|
|
|
2016-08-02 05:32:28 -04:00
|
|
|
FileUtils.mkdir_p(File.dirname(import_upload_path))
|
|
|
|
FileUtils.copy_entry(project_params[:file].path, import_upload_path)
|
2016-06-24 04:50:23 -04:00
|
|
|
|
2016-06-14 14:32:19 -04:00
|
|
|
@project = Gitlab::ImportExport::ProjectCreator.new(project_params[:namespace_id],
|
2016-06-14 06:47:07 -04:00
|
|
|
current_user,
|
2016-08-02 05:32:28 -04:00
|
|
|
import_upload_path,
|
2016-06-14 06:47:07 -04:00
|
|
|
project_params[:path]).execute
|
2016-06-13 14:35:57 -04:00
|
|
|
|
|
|
|
if @project.saved?
|
|
|
|
redirect_to(
|
|
|
|
project_path(@project),
|
|
|
|
notice: "Project '#{@project.name}' is being imported."
|
|
|
|
)
|
|
|
|
else
|
2016-07-07 09:34:45 -04:00
|
|
|
redirect_back_or_default(options: { alert: "Project could not be imported: #{@project.errors.full_messages.join(', ')}" })
|
2016-06-13 14:35:57 -04:00
|
|
|
end
|
2016-04-25 12:00:15 -04:00
|
|
|
end
|
|
|
|
|
2016-05-13 11:03:03 -04:00
|
|
|
private
|
2016-04-25 12:00:15 -04:00
|
|
|
|
2016-06-13 14:35:57 -04:00
|
|
|
def file_is_valid?
|
2016-06-15 11:31:00 -04:00
|
|
|
project_params[:file] && project_params[:file].respond_to?(:read)
|
2016-06-13 14:35:57 -04:00
|
|
|
end
|
|
|
|
|
2016-04-25 12:00:15 -04:00
|
|
|
def verify_gitlab_project_import_enabled
|
|
|
|
render_404 unless gitlab_project_import_enabled?
|
|
|
|
end
|
2016-04-26 11:12:50 -04:00
|
|
|
|
|
|
|
def project_params
|
2016-04-27 09:01:55 -04:00
|
|
|
params.permit(
|
2016-06-14 15:03:14 -04:00
|
|
|
:path, :namespace_id, :file
|
2016-04-26 11:12:50 -04:00
|
|
|
)
|
|
|
|
end
|
2016-08-11 10:59:37 -04:00
|
|
|
|
|
|
|
def authenticate_admin!
|
|
|
|
render_404 unless current_user.is_admin?
|
|
|
|
end
|
2016-04-25 12:00:15 -04:00
|
|
|
end
|