2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class Projects::ForksController < Projects::ApplicationController
|
2016-06-02 11:05:42 +05:30
|
|
|
include ContinueParams
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
# Authorize
|
2018-03-17 18:26:18 +05:30
|
|
|
before_action :whitelist_query_limiting, only: [:create]
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
2017-08-17 22:00:37 +05:30
|
|
|
before_action :authenticate_user!, only: [:new, :create]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-04-02 18:10:28 +05:30
|
|
|
def index
|
|
|
|
base_query = project.forks.includes(:creator)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
forks = ForkProjectsFinder.new(project, params: params.merge(search: params[:filter_projects]), current_user: current_user).execute
|
2016-04-02 18:10:28 +05:30
|
|
|
@total_forks_count = base_query.size
|
2018-03-17 18:26:18 +05:30
|
|
|
@private_forks_count = @total_forks_count - forks.size
|
2016-04-02 18:10:28 +05:30
|
|
|
@public_forks_count = @total_forks_count - @private_forks_count
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@forks = forks.page(params[:page])
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
html: view_to_html_string("projects/forks/_projects", projects: @forks)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def new
|
|
|
|
@namespaces = current_user.manageable_namespaces
|
|
|
|
@namespaces.delete(@project.namespace)
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-04-26 12:48:37 +05:30
|
|
|
def create
|
|
|
|
namespace = Namespace.find(params[:namespace_key])
|
2016-04-02 18:10:28 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
@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
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
if @forked_project.saved? && @forked_project.forked?
|
2015-09-25 12:07:36 +05:30
|
|
|
if @forked_project.import_in_progress?
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_to project_import_path(@forked_project, continue: continue_params)
|
2015-09-25 12:07:36 +05:30
|
|
|
else
|
2016-01-14 18:37:52 +05:30
|
|
|
if continue_params
|
|
|
|
redirect_to continue_params[:to], notice: continue_params[:notice]
|
|
|
|
else
|
2017-09-10 17:25:29 +05:30
|
|
|
redirect_to project_path(@forked_project), notice: "The project '#{@forked_project.name}' was successfully forked."
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
|
|
|
render :error
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def whitelist_query_limiting
|
|
|
|
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42335')
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|