imports_controller.rb 1.22 KB
Newer Older
1 2
class Projects::ImportsController < Projects::ApplicationController
  # Authorize
3 4 5
  before_action :authorize_admin_project!
  before_action :require_no_repo
  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's avatar
Vinnie Okada committed
23
    redirect_to namespace_project_import_path(@project.namespace, @project)
24 25 26 27 28
  end

  def show
    unless @project.import_in_progress?
      if @project.import_finished?
29
        redirect_to(project_path(@project)) and return
30
      else
31 32
        redirect_to(new_namespace_project_import_path(@project.namespace,
                                                      @project)) and return
33 34 35 36 37 38 39
      end
    end
  end

  private

  def require_no_repo
DJ Mountney's avatar
DJ Mountney committed
40
    if @project.repository_exists? && !@project.import_in_progress?
Vinnie Okada's avatar
Vinnie Okada committed
41
      redirect_to(namespace_project_path(@project.namespace, @project)) and return
42 43 44 45 46
    end
  end

  def redirect_if_progress
    if @project.import_in_progress?
Vinnie Okada's avatar
Vinnie Okada committed
47 48
      redirect_to namespace_project_import_path(@project.namespace, @project) &&
        return
49 50 51
    end
  end
end