imports_controller.rb 1.8 KB
Newer Older
1
class Projects::ImportsController < Projects::ApplicationController
2
  include ContinueParams
3

4
  # Authorize
5
  before_action :authorize_admin_project!
6
7
  before_action :require_no_repo, only: [:new, :create]
  before_action :redirect_if_progress, only: [:new, :create]
8
  before_action :redirect_if_no_import, only: :show
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

  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
26
    redirect_to namespace_project_import_path(@project.namespace, @project)
27
28
29
  end

  def show
30
    if @project.import_finished?
31
32
      if continue_params
        redirect_to continue_params[:to], notice: continue_params[:notice]
33
      else
34
        redirect_to namespace_project_path(@project.namespace, @project), notice: finished_notice
35
      end
36
37
38
39
40
41
    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
42

43
      # Render
44
45
46
47
48
    end
  end

  private

49
50
51
52
53
54
55
56
  def finished_notice
    if @project.forked?
      'The project was successfully forked.'
    else
      'The project was successfully imported.'
    end
  end

57
  def require_no_repo
58
    if @project.repository_exists?
59
      redirect_to namespace_project_path(@project.namespace, @project)
60
61
62
63
64
    end
  end

  def redirect_if_progress
    if @project.import_in_progress?
65
66
67
68
69
70
71
      redirect_to namespace_project_import_path(@project.namespace, @project)
    end
  end

  def redirect_if_no_import
    if @project.repository_exists? && @project.no_import?
      redirect_to namespace_project_path(@project.namespace, @project)
72
73
74
    end
  end
end