2014-11-29 22:50:25 +00:00
|
|
|
class Projects::ImportsController < Projects::ApplicationController
|
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :authorize_admin_project!
|
|
|
|
before_action :require_no_repo
|
|
|
|
before_action :redirect_if_progress, except: :show
|
2014-11-29 22:50:25 +00:00
|
|
|
|
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@project.import_url = params[:project][:import_url]
|
|
|
|
|
|
|
|
if @project.save
|
|
|
|
@project.reload
|
|
|
|
|
|
|
|
if @project.import_failed?
|
|
|
|
@project.import_retry
|
|
|
|
else
|
|
|
|
@project.import_start
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project)
|
2014-11-29 22:50:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
unless @project.import_in_progress?
|
|
|
|
if @project.import_finished?
|
2015-03-03 02:11:50 +00:00
|
|
|
redirect_to(project_path(@project)) and return
|
2014-11-29 22:50:25 +00:00
|
|
|
else
|
2015-11-11 15:25:01 +00:00
|
|
|
redirect_to(new_namespace_project_import_path(@project.namespace,
|
|
|
|
@project)) and return
|
2014-11-29 22:50:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def require_no_repo
|
2015-03-09 23:36:41 +00:00
|
|
|
if @project.repository_exists? && !@project.import_in_progress?
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to(namespace_project_path(@project.namespace, @project)) and return
|
2014-11-29 22:50:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_if_progress
|
|
|
|
if @project.import_in_progress?
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project) &&
|
|
|
|
return
|
2014-11-29 22:50:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|