forks_controller.rb 877 Bytes
Newer Older
1
2
class Projects::ForksController < Projects::ApplicationController
  # Authorize
3
4
  before_action :require_non_empty_project
  before_action :authorize_download_code!
5
6
7
8
9
10
11

  def new
    @namespaces = current_user.manageable_namespaces
    @namespaces.delete(@project.namespace)
  end

  def create
Vinnie Okada's avatar
Vinnie Okada committed
12
    namespace = Namespace.find(params[:namespace_key])
13
14
15
    @forked_project = ::Projects::ForkService.new(project, current_user, namespace: namespace).execute

    if @forked_project.saved? && @forked_project.forked?
16
17
18
19
20
21
22
23
      if @forked_project.import_in_progress?
        redirect_to namespace_project_import_path(@forked_project.namespace, @forked_project)
      else
        redirect_to(
          namespace_project_path(@forked_project.namespace, @forked_project),
          notice: 'Project was successfully forked.'
        )
      end
24
25
26
27
28
    else
      render :error
    end
  end
end