2014-11-13 20:06:19 +00:00
|
|
|
class Projects::ForksController < Projects::ApplicationController
|
2016-03-07 09:36:16 +00:00
|
|
|
include ContinueParams
|
2016-03-07 09:06:54 +00:00
|
|
|
|
2014-11-13 20:06:19 +00:00
|
|
|
# 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
|
2016-02-27 00:08:25 +00:00
|
|
|
base_query = project.forks.includes(:creator)
|
2016-01-15 00:58:57 +00:00
|
|
|
|
2016-03-02 17:35:56 +00:00
|
|
|
@forks = base_query.merge(ProjectsFinder.new.execute(current_user))
|
2016-02-27 00:08:25 +00:00
|
|
|
@total_forks_count = base_query.size
|
|
|
|
@private_forks_count = @total_forks_count - @forks.size
|
|
|
|
@public_forks_count = @total_forks_count - @private_forks_count
|
|
|
|
|
|
|
|
@sort = params[:sort] || 'id_desc'
|
2016-03-03 12:09:58 +00:00
|
|
|
@forks = @forks.search(params[:filter_projects]) if params[:filter_projects].present?
|
2016-03-19 21:37:54 +00:00
|
|
|
@forks = @forks.order_by(@sort).page(params[:page])
|
2016-03-03 12:09:58 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
html: view_to_html_string("projects/forks/_projects", projects: @forks)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-01-11 19:44:31 +00:00
|
|
|
end
|
|
|
|
|
2014-11-13 20:06:19 +00:00
|
|
|
def new
|
2016-11-10 01:08:45 +00:00
|
|
|
if current_user.nil?
|
|
|
|
authenticate_user!
|
|
|
|
else
|
|
|
|
@namespaces = current_user.manageable_namespaces
|
|
|
|
@namespaces.delete(@project.namespace)
|
|
|
|
end
|
2014-11-13 20:06:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-01-24 18:02:58 +00:00
|
|
|
namespace = Namespace.find(params[:namespace_key])
|
2016-01-11 20:36:42 +00:00
|
|
|
|
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-08-22 16:38:22 +00:00
|
|
|
redirect_to namespace_project_path(@forked_project.namespace, @forked_project), notice: "The project '#{@forked_project.name}' 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
|
|
|
|
end
|