BigW Consortium Gitlab

gitlab_projects_controller.rb 1.4 KB
Newer Older
1
class Import::GitlabProjectsController < Import::BaseController
2 3
  before_action :verify_gitlab_project_import_enabled

4
  def new
5
    @namespace_id = project_params[:namespace_id]
6
    @namespace_name = Namespace.find(project_params[:namespace_id]).name
7
    @path = project_params[:path]
8 9
  end

10
  def create
11 12 13 14
    unless file_is_valid?
      return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
    end

15
    @project = Gitlab::ImportExport::ProjectCreator.new(project_params[:namespace_id],
16
                                                        current_user,
17
                                                        File.expand_path(project_params[:file].path),
18
                                                        project_params[:path]).execute
19 20 21 22 23 24 25

    if @project.saved?
      redirect_to(
        project_path(@project),
        notice: "Project '#{@project.name}' is being imported."
      )
    else
26
      redirect_to(
27 28
        new_import_gitlab_project_path,
        alert: "Project could not be imported: #{@project.errors.full_messages.join(', ')}"
29
      )
30
    end
31 32
  end

33
  private
34

35
  def file_is_valid?
36
    project_params[:file] && project_params[:file].respond_to?(:read)
37 38
  end

39 40 41
  def verify_gitlab_project_import_enabled
    render_404 unless gitlab_project_import_enabled?
  end
42 43

  def project_params
44
    params.permit(
45
      :path, :namespace_id, :file
46 47
    )
  end
48
end