2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2018-01-15 10:21:04 -05:00
|
|
|
before_action :whitelist_query_limiting, only: [:create]
|
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
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
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-09-19 02:55:22 -04:00
|
|
|
forks = ForkProjectsFinder.new(project, params: params.merge(search: params[:filter_projects]), current_user: current_user).execute
|
2016-02-26 19:08:25 -05:00
|
|
|
@total_forks_count = base_query.size
|
2017-09-19 02:55:22 -04:00
|
|
|
@private_forks_count = @total_forks_count - forks.size
|
2016-02-26 19:08:25 -05:00
|
|
|
@public_forks_count = @total_forks_count - @private_forks_count
|
|
|
|
|
2017-09-19 02:55:22 -04:00
|
|
|
@forks = forks.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
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-01-11 14:44:31 -05:00
|
|
|
|
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
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2014-11-13 15:06:19 -05:00
|
|
|
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?
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_import_path(@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
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_path(@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
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-01-15 10:21:04 -05:00
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42335')
|
|
|
|
end
|
2014-11-13 15:06:19 -05:00
|
|
|
end
|