debian-mirror-gitlab/app/controllers/projects/forks_controller.rb

68 lines
2.4 KiB
Ruby
Raw Normal View History

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
2019-12-04 20:38:33 +05:30
include RendersMemberAccess
2016-06-02 11:05:42 +05:30
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
2019-12-04 20:38:33 +05:30
@total_forks_count = project.forks.size
@public_forks_count = project.forks.public_only.size
@private_forks_count = @total_forks_count - project.forks.public_and_internal_only.size
@internal_forks_count = @total_forks_count - @public_forks_count - @private_forks_count
2016-04-02 18:10:28 +05:30
2019-12-04 20:38:33 +05:30
@forks = ForkProjectsFinder.new(project, params: params.merge(search: params[:filter_projects]), current_user: current_user).execute
@forks = @forks.includes(:route, :creator, :group, namespace: [:route, :owner])
.page(params[:page])
2016-04-02 18:10:28 +05:30
2019-12-04 20:38:33 +05:30
prepare_projects_for_rendering(@forks)
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
@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
2019-09-30 21:07:59 +05:30
if !@forked_project.saved? || !@forked_project.forked?
2015-04-26 12:48:37 +05:30
render :error
2019-09-30 21:07:59 +05:30
elsif @forked_project.import_in_progress?
redirect_to project_import_path(@forked_project, continue: continue_params)
elsif continue_params[:to]
redirect_to continue_params[:to], notice: continue_params[:notice]
else
redirect_to project_path(@forked_project), notice: "The project '#{@forked_project.name}' was successfully forked."
2015-04-26 12:48:37 +05:30
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
2019-12-04 20:38:33 +05:30
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-foss/issues/42335')
2018-03-17 18:26:18 +05:30
end
2015-04-26 12:48:37 +05:30
end