Fix project creation for user endpoint bug

In this endpoint the `jobs_enabled` parameter must be
translated to `builds_enabled` before being passed to
the `Projects::CreateService`.
This commit is contained in:
Mark Fletcher 2018-04-21 19:02:21 +01:00
parent c212908aad
commit 5716167775
3 changed files with 15 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
title: Fix project creation for user endpoint when jobs_enabled parameter supplied
merge_request:
author:
type: fixed

View File

@ -74,6 +74,11 @@ module API
present options[:with].prepare_relation(projects, options), options
end
def translate_params_for_compatibility(params)
params[:builds_enabled] = params.delete(:jobs_enabled) if params.key?(:jobs_enabled)
params
end
end
resource :users, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
@ -123,7 +128,7 @@ module API
end
post do
attrs = declared_params(include_missing: false)
attrs[:builds_enabled] = attrs.delete(:jobs_enabled) if attrs.key?(:jobs_enabled)
attrs = translate_params_for_compatibility(attrs)
project = ::Projects::CreateService.new(current_user, attrs).execute
if project.saved?
@ -155,6 +160,7 @@ module API
not_found!('User') unless user
attrs = declared_params(include_missing: false)
attrs = translate_params_for_compatibility(attrs)
project = ::Projects::CreateService.new(user, attrs).execute
if project.saved?
@ -276,7 +282,7 @@ module API
authorize! :rename_project, user_project if attrs[:name].present?
authorize! :change_visibility_level, user_project if attrs[:visibility].present?
attrs[:builds_enabled] = attrs.delete(:jobs_enabled) if attrs.key?(:jobs_enabled)
attrs = translate_params_for_compatibility(attrs)
result = ::Projects::UpdateService.new(user_project, current_user, attrs).execute

View File

@ -685,7 +685,8 @@ describe API::Projects do
issues_enabled: false,
merge_requests_enabled: false,
wiki_enabled: false,
request_access_enabled: true
request_access_enabled: true,
jobs_enabled: true
})
post api("/projects/user/#{user.id}", admin), project