BigW Consortium Gitlab

imports_controller.rb 1.63 KB
Newer Older
1 2
class Projects::ImportsController < Projects::ApplicationController
  # Authorize
3
  before_action :authorize_admin_project!
4
  before_action :require_no_repo, except: :show
5
  before_action :redirect_if_progress, except: :show
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

  def new
  end

  def create
    @project.import_url = params[:project][:import_url]

    if @project.save
      @project.reload

      if @project.import_failed?
        @project.import_retry
      else
        @project.import_start
      end
    end

Vinnie Okada committed
23
    redirect_to namespace_project_import_path(@project.namespace, @project)
24 25 26
  end

  def show
27 28 29
    if @project.repository_exists? || @project.import_finished?
      if continue_params
        redirect_to continue_params[:to], notice: continue_params[:notice]
30
      else
31
        redirect_to project_path(@project), notice: "The project was successfully forked."
32
      end
33 34 35 36 37 38 39
    elsif @project.import_failed?
      redirect_to new_namespace_project_import_path(@project.namespace, @project)
    else
      if continue_params && continue_params[:notice_now]
        flash.now[:notice] = continue_params[:notice_now]
      end
      # Render
40 41 42 43 44
    end
  end

  private

45
  def continue_params
46 47 48 49 50 51
    continue_params = params[:continue]
    if continue_params
      continue_params.permit(:to, :notice, :notice_now)
    else
      nil
    end
52 53
  end

54
  def require_no_repo
55
    if @project.repository_exists? && !@project.import_in_progress?
56
      redirect_to(namespace_project_path(@project.namespace, @project))
57 58 59 60 61
    end
  end

  def redirect_if_progress
    if @project.import_in_progress?
Vinnie Okada committed
62 63
      redirect_to namespace_project_import_path(@project.namespace, @project) &&
        return
64 65 66
    end
  end
end