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

64 lines
2.1 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
class Projects::ForksController < Projects::ApplicationController
# Authorize
2015-09-11 14:41:01 +05:30
before_action :require_non_empty_project
before_action :authorize_download_code!
2015-04-26 12:48:37 +05:30
2016-04-02 18:10:28 +05:30
def index
base_query = project.forks.includes(:creator)
@forks = if current_user
base_query.where('projects.visibility_level IN (?) OR projects.id IN (?)',
Project.public_and_internal_levels,
current_user.authorized_projects.pluck(:id))
else
base_query.where('projects.visibility_level = ?', Project::PUBLIC)
end
@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'
@forks = @forks.order_by(@sort).page(params[:page]).per(PER_PAGE)
end
2015-04-26 12:48:37 +05:30
def new
@namespaces = current_user.manageable_namespaces
@namespaces.delete(@project.namespace)
end
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
if @forked_project.saved? && @forked_project.forked?
2015-09-25 12:07:36 +05:30
if @forked_project.import_in_progress?
redirect_to namespace_project_import_path(@forked_project.namespace, @forked_project, continue: continue_params)
2015-09-25 12:07:36 +05:30
else
if continue_params
redirect_to continue_params[:to], notice: continue_params[:notice]
else
2016-04-02 18:10:28 +05:30
redirect_to namespace_project_path(@forked_project.namespace, @forked_project), notice: "The project '#{@forked_project.name}' was successfully forked."
end
2015-09-25 12:07:36 +05:30
end
2015-04-26 12:48:37 +05:30
else
render :error
end
end
private
def continue_params
continue_params = params[:continue]
if continue_params
continue_params.permit(:to, :notice, :notice_now)
else
nil
end
end
2015-04-26 12:48:37 +05:30
end