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

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

  def show
28
    if @project.import_finished?
29
30
      if continue_params
        redirect_to continue_params[:to], notice: continue_params[:notice]
31
      else
32
        redirect_to namespace_project_path(@project.namespace, @project), notice: finished_notice
33
      end
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
40

41
      # Render
42
43
44
45
46
    end
  end

  private

47
  def continue_params
48
    continue_params = params[:continue]
49

50
51
52
53
54
    if continue_params
      continue_params.permit(:to, :notice, :notice_now)
    else
      nil
    end
55
56
  end

57
58
59
60
61
62
63
64
  def finished_notice
    if @project.forked?
      'The project was successfully forked.'
    else
      'The project was successfully imported.'
    end
  end

65
  def require_no_repo
66
    if @project.repository_exists?
67
      redirect_to namespace_project_path(@project.namespace, @project)
68
69
70
71
72
    end
  end

  def redirect_if_progress
    if @project.import_in_progress?
73
74
75
76
77
78
79
      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)
80
81
82
    end
  end
end