diff options
author | James Lopez <james@jameslopez.es> | 2016-06-13 21:35:57 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-06-13 21:35:57 +0300 |
commit | 903da377553d37ac3263055fcc634351cc4750d4 (patch) | |
tree | 9f8db98779f462876fd0d69739fb426fbeb40dd1 /app/controllers/import | |
parent | f449eeb6f1d56c1a00f4d9043680ee8033a78afe (diff) |
WIP - starting refactoring import/export to use services
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/gitlab_projects_controller.rb | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb index a4ac55cd2a4..90b4ff8b2ca 100644 --- a/app/controllers/import/gitlab_projects_controller.rb +++ b/app/controllers/import/gitlab_projects_controller.rb @@ -2,24 +2,41 @@ class Import::GitlabProjectsController < Import::BaseController before_action :verify_gitlab_project_import_enabled before_action :verify_project_and_namespace_access - rescue_from OAuth::Error, with: :gitlab_project_unauthorized - def new @namespace_id = project_params[:namespace_id] @path = project_params[:path] end def create + unless file_is_valid? + return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." }) + end + @project = Project.create_from_import_job(current_user_id: current_user.id, tmp_file: File.expand_path(params[:file].path), namespace_id: project_params[:namespace_id], project_path: project_params[:path]) - redirect_to dashboard_projects_path + @project = Gitlab::GitlabImport::ProjectCreator.new(repo, namespace, current_user, access_params).execute + + flash[:notice] = "The project import has been started." + + if @project.saved? + redirect_to( + project_path(@project), + notice: "Project '#{@project.name}' is being imported." + ) + else + render 'new' + end end private + def file_is_valid? + params[:file].respond_to?(:read) && params[:file].content_type == 'application/x-gzip' + end + def verify_project_and_namespace_access unless namespace_access? render_403 @@ -27,7 +44,7 @@ class Import::GitlabProjectsController < Import::BaseController end def namespace_access? - current_user.can?(:create_projects, Namespace.find(project_params[:namespace_id])) + can?(current_user, :create_projects, Namespace.find(project_params[:namespace_id])) end def verify_gitlab_project_import_enabled |