BigW Consortium Gitlab

Commit 903da377 by James Lopez

WIP - starting refactoring import/export to use services

parent f449eeb6
......@@ -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
......
- page_title "GitLab Import"
- header_title "Projects", root_path
%h3.page-title
%i.fa.fa-gitlab
= icon('gitlab')
Import projects from GitLab
%hr
= form_tag import_gitlab_project_path, class: 'form-horizontal', multipart: true do
%p
Project will be imported to path #{@path}
%p
To get started add your exported project file below:
.form-group
= hidden_field_tag :namespace_id, @namespace_id
......
......@@ -11,7 +11,7 @@ module Gitlab
end
def execute
project = ::Projects::CreateService.new(
::Projects::CreateService.new(
current_user,
name: repo["name"],
path: repo["path"],
......@@ -22,8 +22,6 @@ module Gitlab
import_source: repo["path_with_namespace"],
import_url: repo["http_url_to_repo"].sub("://", "://oauth2:#{@session_data[:gitlab_access_token]}@")
).execute
project
end
end
end
......
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment