2014-11-13 20:06:19 +00:00
|
|
|
class Projects::ForksController < Projects::ApplicationController
|
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
2014-11-13 20:06:19 +00:00
|
|
|
|
2016-01-11 19:44:31 +00:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
2014-11-13 20:06:19 +00:00
|
|
|
def new
|
|
|
|
@namespaces = current_user.manageable_namespaces
|
|
|
|
@namespaces.delete(@project.namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-01-24 18:02:58 +00:00
|
|
|
namespace = Namespace.find(params[:namespace_key])
|
2015-12-21 10:57:51 +00:00
|
|
|
|
|
|
|
@forked_project = namespace.projects.find_by(path: project.path)
|
|
|
|
@forked_project = nil unless @forked_project && @forked_project.forked_from_project == project
|
|
|
|
|
|
|
|
@forked_project ||= ::Projects::ForkService.new(project, current_user, namespace: namespace).execute
|
2014-11-13 20:06:19 +00:00
|
|
|
|
|
|
|
if @forked_project.saved? && @forked_project.forked?
|
2015-09-01 07:56:40 +00:00
|
|
|
if @forked_project.import_in_progress?
|
2015-12-18 09:03:34 +00:00
|
|
|
redirect_to namespace_project_import_path(@forked_project.namespace, @forked_project, continue: continue_params)
|
2015-09-01 07:56:40 +00:00
|
|
|
else
|
2015-12-18 09:03:34 +00:00
|
|
|
if continue_params
|
|
|
|
redirect_to continue_params[:to], notice: continue_params[:notice]
|
|
|
|
else
|
2015-12-18 15:14:12 +00:00
|
|
|
redirect_to namespace_project_path(@forked_project.namespace, @forked_project), notice: "The project was successfully forked."
|
2015-12-18 09:03:34 +00:00
|
|
|
end
|
2015-09-01 07:56:40 +00:00
|
|
|
end
|
2014-11-13 20:06:19 +00:00
|
|
|
else
|
|
|
|
render :error
|
|
|
|
end
|
|
|
|
end
|
2015-12-18 09:03:34 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def continue_params
|
2015-12-18 15:14:12 +00:00
|
|
|
continue_params = params[:continue]
|
|
|
|
if continue_params
|
|
|
|
continue_params.permit(:to, :notice, :notice_now)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
2015-12-18 09:03:34 +00:00
|
|
|
end
|
2014-11-13 20:06:19 +00:00
|
|
|
end
|