debian-mirror-gitlab/app/controllers/projects/imports_controller.rb

76 lines
1.8 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
class Projects::ImportsController < Projects::ApplicationController
2016-06-02 11:05:42 +05:30
include ContinueParams
2015-04-26 12:48:37 +05:30
# Authorize
2015-09-11 14:41:01 +05:30
before_action :authorize_admin_project!
2016-02-05 20:25:01 +05:30
before_action :require_no_repo, only: [:new, :create]
before_action :redirect_if_progress, only: [:new, :create]
2016-04-02 18:10:28 +05:30
before_action :redirect_if_no_import, only: :show
2015-04-26 12:48:37 +05:30
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
2016-06-02 11:05:42 +05:30
@project.add_import_job
2015-04-26 12:48:37 +05:30
end
end
redirect_to namespace_project_import_path(@project.namespace, @project)
end
def show
2016-02-05 20:25:01 +05:30
if @project.import_finished?
if continue_params
redirect_to continue_params[:to], notice: continue_params[:notice]
2015-04-26 12:48:37 +05:30
else
2016-02-05 20:25:01 +05:30
redirect_to namespace_project_path(@project.namespace, @project), notice: finished_notice
2015-04-26 12:48:37 +05:30
end
elsif @project.import_failed?
redirect_to new_namespace_project_import_path(@project.namespace, @project)
else
if continue_params && continue_params[:notice_now]
flash.now[:notice] = continue_params[:notice_now]
end
2016-02-05 20:25:01 +05:30
# Render
2015-04-26 12:48:37 +05:30
end
end
private
2016-02-05 20:25:01 +05:30
def finished_notice
if @project.forked?
'The project was successfully forked.'
else
'The project was successfully imported.'
end
end
2015-04-26 12:48:37 +05:30
def require_no_repo
2016-02-05 20:25:01 +05:30
if @project.repository_exists?
2016-04-02 18:10:28 +05:30
redirect_to namespace_project_path(@project.namespace, @project)
2015-04-26 12:48:37 +05:30
end
end
def redirect_if_progress
if @project.import_in_progress?
2016-04-02 18:10:28 +05:30
redirect_to namespace_project_import_path(@project.namespace, @project)
end
end
def redirect_if_no_import
if @project.repository_exists? && @project.no_import?
redirect_to namespace_project_path(@project.namespace, @project)
2015-04-26 12:48:37 +05:30
end
end
end