Merge branch 'fix/template-project-visibility' into 'master'

Respect description and visibility when creating project from template

Closes #42601

See merge request gitlab-org/gitlab-ce!16820
This commit is contained in:
Douwe Maan 2018-02-14 12:38:51 +00:00
commit 44dc11f12e
5 changed files with 24 additions and 36 deletions

View file

@ -5,11 +5,15 @@ module Projects
end
def execute
params[:file] = Gitlab::ProjectTemplate.find(params[:template_name]).file
template_name = params.delete(:template_name)
file = Gitlab::ProjectTemplate.find(template_name).file
params[:file] = file
GitlabProjectsImportService.new(current_user, params).execute
GitlabProjectsImportService.new(@current_user, @params).execute
ensure
params[:file]&.close
file&.close
end
end
end

View file

@ -11,12 +11,14 @@ module Projects
def execute
FileUtils.mkdir_p(File.dirname(import_upload_path))
file = params.delete(:file)
FileUtils.copy_entry(file.path, import_upload_path)
Gitlab::ImportExport::ProjectCreator.new(params[:namespace_id],
current_user,
import_upload_path,
params[:path]).execute
params[:import_type] = 'gitlab_project'
params[:import_source] = import_upload_path
::Projects::CreateService.new(current_user, params).execute
end
private
@ -28,9 +30,5 @@ module Projects
def tmp_filename
SecureRandom.hex
end
def file
params[:file]
end
end
end

View file

@ -0,0 +1,5 @@
---
title: Respect description and visibility when creating project from template
merge_request: 16820
author: George Tsiolis
type: fixed

View file

@ -1,23 +0,0 @@
module Gitlab
module ImportExport
class ProjectCreator
def initialize(namespace_id, current_user, file, project_path)
@namespace_id = namespace_id
@current_user = current_user
@file = file
@project_path = project_path
end
def execute
::Projects::CreateService.new(
@current_user,
name: @project_path,
path: @project_path,
namespace_id: @namespace_id,
import_type: "gitlab_project",
import_source: @file
).execute
end
end
end
end

View file

@ -4,8 +4,10 @@ describe Projects::CreateFromTemplateService do
let(:user) { create(:user) }
let(:project_params) do
{
path: user.to_param,
template_name: 'rails'
path: user.to_param,
template_name: 'rails',
description: 'project description',
visibility_level: Gitlab::VisibilityLevel::PRIVATE
}
end
@ -22,5 +24,7 @@ describe Projects::CreateFromTemplateService do
expect(project).to be_saved
expect(project.scheduled?).to be(true)
expect(project.description).to match('project description')
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
end
end