Commit b7c54d3b authored by Michael Kozono's avatar Michael Kozono

Merge branch 'issue_222462' into 'master'

Fix creating/updating issues with epic_iid parameter on API

See merge request gitlab-org/gitlab!34641
parents 53be6217 6f899c13
---
title: Fix creating/updating issues with epic_iid parameter on API
merge_request: 34641
author:
type: fixed
...@@ -15,8 +15,13 @@ module EE ...@@ -15,8 +15,13 @@ module EE
iid = params.delete(:epic_iid) iid = params.delete(:epic_iid)
if iid.present? if iid.present?
epic = EpicsFinder.new(current_user, group_id: group.id, iids: [iid]).first group_id = user_project&.group&.id
not_found!('Epic') unless epic
raise_epic_not_found! unless group_id
epic = EpicsFinder.new(current_user, group_id: group_id).find_by(iid: iid) # rubocop: disable CodeReuse/ActiveRecord
raise_epic_not_found! unless epic
params[:epic_id] = epic.id params[:epic_id] = epic.id
end end
...@@ -24,6 +29,10 @@ module EE ...@@ -24,6 +29,10 @@ module EE
super super
end end
def raise_epic_not_found!
not_found!('Epic')
end
end end
end end
end end
......
...@@ -254,11 +254,26 @@ RSpec.describe API::Issues, :mailer do ...@@ -254,11 +254,26 @@ RSpec.describe API::Issues, :mailer do
group.add_owner(user) group.add_owner(user)
end end
it 'sets epic on issue' do context 'with epic_id parameter' do
request let(:params) { { title: 'issue with epic', epic_id: epic.id } }
it 'sets epic on issue' do
request
expect(response).to have_gitlab_http_status(:success)
expect(json_response['epic_iid']).to eq(epic.iid)
end
end
context 'with deprecated epic_iid parameter' do
let(:params) { { title: 'issue with epic', epic_iid: epic.iid } }
it 'sets epic on issue' do
request
expect(response).to have_gitlab_http_status(:success) expect(response).to have_gitlab_http_status(:success)
expect(json_response['epic_iid']).to eq(epic.iid) expect(json_response['epic_iid']).to eq(epic.iid)
end
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