diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-17 00:06:11 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-17 00:06:11 +0000 |
commit | 48c77599ca5d833ce01ca310af4887200875174f (patch) | |
tree | aade7cdac1b3f5ee266f5df1caf3b745dcd14a8d /app/services/projects | |
parent | 274ea604fcd43ecccfba04756a9475a3efa47de0 (diff) | |
download | gitlab-ce-48c77599ca5d833ce01ca310af4887200875174f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/projects')
-rw-r--r-- | app/services/projects/create_from_template_service.rb | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/app/services/projects/create_from_template_service.rb b/app/services/projects/create_from_template_service.rb index 31977a7c76a..91ece024e13 100644 --- a/app/services/projects/create_from_template_service.rb +++ b/app/services/projects/create_from_template_service.rb @@ -9,7 +9,9 @@ module Projects end def execute - file = Gitlab::ProjectTemplate.find(template_name)&.file + return project unless validate_template! + + file = built_in_template&.file override_params = params.dup params[:file] = file @@ -24,6 +26,25 @@ module Projects params.delete(:template_name).presence end end + + private + + def validate_template! + return true if built_in_template + + project.errors.add(:template_name, _("'%{template_name}' is unknown or invalid" % { template_name: template_name })) + false + end + + def built_in_template + strong_memoize(:built_in_template) do + Gitlab::ProjectTemplate.find(template_name) + end + end + + def project + @project ||= ::Project.new(namespace_id: params[:namespace_id]) + end end end |