Commit 0bb54a0b authored by Mara Sophie Grosch's avatar Mara Sophie Grosch Committed by Mayra Cabrera

Fixes #196172: manual IID should render conflict

When creating an issue via the API with a manual IID which is already
in use, the server would send a server error response instead of a
conflict response.
parent 531bebc9
---
title: 'Fix Issue API: creating with manual IID returns conflict when IID already
in use'
merge_request: 22788
author: Mara Sophie Grosch
type: fixed
......@@ -220,18 +220,22 @@ module API
issue_params = convert_parameters_from_legacy_format(issue_params)
issue = ::Issues::CreateService.new(user_project,
current_user,
issue_params.merge(request: request, api: true)).execute
if issue.spam?
render_api_error!({ error: 'Spam detected' }, 400)
end
if issue.valid?
present issue, with: Entities::Issue, current_user: current_user, project: user_project
else
render_validation_error!(issue)
begin
issue = ::Issues::CreateService.new(user_project,
current_user,
issue_params.merge(request: request, api: true)).execute
if issue.spam?
render_api_error!({ error: 'Spam detected' }, 400)
end
if issue.valid?
present issue, with: Entities::Issue, current_user: current_user, project: user_project
else
render_validation_error!(issue)
end
rescue ::ActiveRecord::RecordNotUnique
render_api_error!('Duplicated issue', 409)
end
end
......
......@@ -160,6 +160,16 @@ describe API::Issues do
expect(json_response['iid']).not_to eq 9001
end
end
context 'when an issue with the same IID exists on database' do
it 'returns 409' do
post api("/projects/#{project.id}/issues", admin),
params: { title: 'new issue', iid: issue.iid }
expect(response).to have_gitlab_http_status(409)
expect(json_response['message']).to eq 'Duplicated issue'
end
end
end
it 'creates a new project issue' do
......
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