WIP - starting refactoring import/export to use services
This commit is contained in:
parent
f449eeb6f1
commit
903da37755
|
@ -2,24 +2,41 @@ class Import::GitlabProjectsController < Import::BaseController
|
||||||
before_action :verify_gitlab_project_import_enabled
|
before_action :verify_gitlab_project_import_enabled
|
||||||
before_action :verify_project_and_namespace_access
|
before_action :verify_project_and_namespace_access
|
||||||
|
|
||||||
rescue_from OAuth::Error, with: :gitlab_project_unauthorized
|
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@namespace_id = project_params[:namespace_id]
|
@namespace_id = project_params[:namespace_id]
|
||||||
@path = project_params[:path]
|
@path = project_params[:path]
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
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,
|
@project = Project.create_from_import_job(current_user_id: current_user.id,
|
||||||
tmp_file: File.expand_path(params[:file].path),
|
tmp_file: File.expand_path(params[:file].path),
|
||||||
namespace_id: project_params[:namespace_id],
|
namespace_id: project_params[:namespace_id],
|
||||||
project_path: project_params[:path])
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def file_is_valid?
|
||||||
|
params[:file].respond_to?(:read) && params[:file].content_type == 'application/x-gzip'
|
||||||
|
end
|
||||||
|
|
||||||
def verify_project_and_namespace_access
|
def verify_project_and_namespace_access
|
||||||
unless namespace_access?
|
unless namespace_access?
|
||||||
render_403
|
render_403
|
||||||
|
@ -27,7 +44,7 @@ class Import::GitlabProjectsController < Import::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def namespace_access?
|
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
|
end
|
||||||
|
|
||||||
def verify_gitlab_project_import_enabled
|
def verify_gitlab_project_import_enabled
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
- page_title "GitLab Import"
|
- page_title "GitLab Import"
|
||||||
- header_title "Projects", root_path
|
- header_title "Projects", root_path
|
||||||
%h3.page-title
|
%h3.page-title
|
||||||
%i.fa.fa-gitlab
|
= icon('gitlab')
|
||||||
Import projects from GitLab
|
Import projects from GitLab
|
||||||
%hr
|
%hr
|
||||||
|
|
||||||
= form_tag import_gitlab_project_path, class: 'form-horizontal', multipart: true do
|
= form_tag import_gitlab_project_path, class: 'form-horizontal', multipart: true do
|
||||||
|
%p
|
||||||
|
Project will be imported to path #{@path}
|
||||||
|
|
||||||
%p
|
%p
|
||||||
To get started add your exported project file below:
|
To get started add your exported project file below:
|
||||||
.form-group
|
.form-group
|
||||||
|
|
|
@ -11,7 +11,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
project = ::Projects::CreateService.new(
|
::Projects::CreateService.new(
|
||||||
current_user,
|
current_user,
|
||||||
name: repo["name"],
|
name: repo["name"],
|
||||||
path: repo["path"],
|
path: repo["path"],
|
||||||
|
@ -22,8 +22,6 @@ module Gitlab
|
||||||
import_source: repo["path_with_namespace"],
|
import_source: repo["path_with_namespace"],
|
||||||
import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{@session_data[:gitlab_access_token]}@")
|
import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{@session_data[:gitlab_access_token]}@")
|
||||||
).execute
|
).execute
|
||||||
|
|
||||||
project
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
module Gitlab
|
||||||
|
module ImportExport
|
||||||
|
class ProjectCreator
|
||||||
|
|
||||||
|
def initialize(namespace_id, current_user, )
|
||||||
|
@repo = repo
|
||||||
|
@namespace = Namespace.find_by_id(namespace_id)
|
||||||
|
@current_user = current_user
|
||||||
|
@user_map = user_map
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
::Projects::CreateService.new(
|
||||||
|
current_user,
|
||||||
|
name: repo.name,
|
||||||
|
path: repo.name,
|
||||||
|
description: repo.summary,
|
||||||
|
namespace: namespace,
|
||||||
|
creator: current_user,
|
||||||
|
visibility_level: Gitlab::VisibilityLevel::PUBLIC,
|
||||||
|
import_type: "google_code",
|
||||||
|
import_source: repo.name,
|
||||||
|
import_url: repo.import_url,
|
||||||
|
import_data: { data: { 'repo' => repo.raw_data, 'user_map' => user_map } }
|
||||||
|
).execute
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue