Commit 44dc11f1 authored by Douwe Maan's avatar Douwe Maan

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
parents 12447f12 b5db9562
...@@ -5,11 +5,15 @@ module Projects ...@@ -5,11 +5,15 @@ module Projects
end end
def execute 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 ensure
params[:file]&.close file&.close
end end
end end
end end
...@@ -11,12 +11,14 @@ module Projects ...@@ -11,12 +11,14 @@ module Projects
def execute def execute
FileUtils.mkdir_p(File.dirname(import_upload_path)) FileUtils.mkdir_p(File.dirname(import_upload_path))
file = params.delete(:file)
FileUtils.copy_entry(file.path, import_upload_path) FileUtils.copy_entry(file.path, import_upload_path)
Gitlab::ImportExport::ProjectCreator.new(params[:namespace_id], params[:import_type] = 'gitlab_project'
current_user, params[:import_source] = import_upload_path
import_upload_path,
params[:path]).execute ::Projects::CreateService.new(current_user, params).execute
end end
private private
...@@ -28,9 +30,5 @@ module Projects ...@@ -28,9 +30,5 @@ module Projects
def tmp_filename def tmp_filename
SecureRandom.hex SecureRandom.hex
end end
def file
params[:file]
end
end end
end end
---
title: Respect description and visibility when creating project from template
merge_request: 16820
author: George Tsiolis
type: fixed
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
...@@ -5,7 +5,9 @@ describe Projects::CreateFromTemplateService do ...@@ -5,7 +5,9 @@ describe Projects::CreateFromTemplateService do
let(:project_params) do let(:project_params) do
{ {
path: user.to_param, path: user.to_param,
template_name: 'rails' template_name: 'rails',
description: 'project description',
visibility_level: Gitlab::VisibilityLevel::PRIVATE
} }
end end
...@@ -22,5 +24,7 @@ describe Projects::CreateFromTemplateService do ...@@ -22,5 +24,7 @@ describe Projects::CreateFromTemplateService do
expect(project).to be_saved expect(project).to be_saved
expect(project.scheduled?).to be(true) expect(project.scheduled?).to be(true)
expect(project.description).to match('project description')
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
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