2014-11-29 17:50:25 -05:00
|
|
|
class Projects::ImportsController < Projects::ApplicationController
|
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_admin_project!
|
|
|
|
before_action :require_no_repo
|
|
|
|
before_action :redirect_if_progress, except: :show
|
2014-11-29 17:50:25 -05: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 13:02:58 -05:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project)
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
unless @project.import_in_progress?
|
|
|
|
if @project.import_finished?
|
2015-03-02 21:11:50 -05:00
|
|
|
redirect_to(project_path(@project)) and return
|
2014-11-29 17:50:25 -05:00
|
|
|
else
|
2015-11-11 10:25:01 -05:00
|
|
|
redirect_to(new_namespace_project_import_path(@project.namespace,
|
|
|
|
@project)) and return
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def require_no_repo
|
2015-03-09 19:36:41 -04:00
|
|
|
if @project.repository_exists? && !@project.import_in_progress?
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to(namespace_project_path(@project.namespace, @project)) and return
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_if_progress
|
|
|
|
if @project.import_in_progress?
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project) &&
|
|
|
|
return
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|