2014-11-13 15:06:19 -05:00
|
|
|
class Projects::ForksController < Projects::ApplicationController
|
2016-03-07 04:36:16 -05:00
|
|
|
include ContinueParams
|
2016-03-07 04:06:54 -05:00
|
|
|
|
2014-11-13 15:06:19 -05:00
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
2016-11-14 17:59:11 -05:00
|
|
|
before_action :authenticate_user!, only: [:new, :create]
|
2014-11-13 15:06:19 -05:00
|
|
|
|
2016-01-11 14:44:31 -05:00
|
|
|
def index
|
2016-02-26 19:08:25 -05:00
|
|
|
base_query = project.forks.includes(:creator)
|
2016-01-14 19:58:57 -05:00
|
|
|
|
2017-03-03 05:35:04 -05:00
|
|
|
@forks = base_query.merge(ProjectsFinder.new(current_user: current_user).execute)
|
2016-02-26 19:08:25 -05: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 07:09:58 -05:00
|
|
|
@forks = @forks.search(params[:filter_projects]) if params[:filter_projects].present?
|
2016-03-19 17:37:54 -04:00
|
|
|
@forks = @forks.order_by(@sort).page(params[:page])
|
2016-03-03 07:09:58 -05: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 14:44:31 -05:00
|
|
|
end
|
|
|
|
|
2014-11-13 15:06:19 -05:00
|
|
|
def new
|
2016-11-12 03:16:07 -05:00
|
|
|
@namespaces = current_user.manageable_namespaces
|
|
|
|
@namespaces.delete(@project.namespace)
|
2014-11-13 15:06:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-01-24 13:02:58 -05:00
|
|
|
namespace = Namespace.find(params[:namespace_key])
|
2016-01-11 15:36:42 -05:00
|
|
|
|
2015-12-21 05:57:51 -05: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 15:06:19 -05:00
|
|
|
|
|
|
|
if @forked_project.saved? && @forked_project.forked?
|
2015-09-01 03:56:40 -04:00
|
|
|
if @forked_project.import_in_progress?
|
2015-12-18 04:03:34 -05:00
|
|
|
redirect_to namespace_project_import_path(@forked_project.namespace, @forked_project, continue: continue_params)
|
2015-09-01 03:56:40 -04:00
|
|
|
else
|
2015-12-18 04:03:34 -05:00
|
|
|
if continue_params
|
|
|
|
redirect_to continue_params[:to], notice: continue_params[:notice]
|
|
|
|
else
|
2015-08-22 12:38:22 -04:00
|
|
|
redirect_to namespace_project_path(@forked_project.namespace, @forked_project), notice: "The project '#{@forked_project.name}' was successfully forked."
|
2015-12-18 04:03:34 -05:00
|
|
|
end
|
2015-09-01 03:56:40 -04:00
|
|
|
end
|
2014-11-13 15:06:19 -05:00
|
|
|
else
|
|
|
|
render :error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|