Commit 8cc4716d authored by Felipe Artur's avatar Felipe Artur

Do not allow to create epic when parent reached hierarchy limit

Return error when trying to create epic as child of
another epic that has reached hierarchy limit
parent 5567b773
...@@ -362,7 +362,7 @@ module EE ...@@ -362,7 +362,7 @@ module EE
private :validate_parent private :validate_parent
def level_depth_exceeded?(parent_epic) def level_depth_exceeded?(parent_epic)
hierarchy.max_descendants_depth.to_i + parent_epic.ancestors.count >= MAX_HIERARCHY_DEPTH hierarchy.max_descendants_depth.to_i + parent_epic.base_and_ancestors.count >= MAX_HIERARCHY_DEPTH
end end
private :level_depth_exceeded? private :level_depth_exceeded?
...@@ -371,6 +371,5 @@ module EE ...@@ -371,6 +371,5 @@ module EE
hierarchy.base_and_ancestors(hierarchy_order: :asc) hierarchy.base_and_ancestors(hierarchy_order: :asc)
end end
private :base_and_ancestors
end end
end end
---
title: Fix child epics depth validation
merge_request: 22729
author:
type: fixed
...@@ -84,7 +84,7 @@ module API ...@@ -84,7 +84,7 @@ module API
if child_epic.valid? if child_epic.valid?
present child_epic, with: EE::API::Entities::LinkedEpic, user: current_user present child_epic, with: EE::API::Entities::LinkedEpic, user: current_user
else else
render_validation_error!(epic) render_validation_error!(child_epic)
end end
end end
......
...@@ -128,8 +128,7 @@ describe Epic do ...@@ -128,8 +128,7 @@ describe Epic do
epic3 = create(:epic, group: group, parent: epic2) epic3 = create(:epic, group: group, parent: epic2)
epic4 = create(:epic, group: group, parent: epic3) epic4 = create(:epic, group: group, parent: epic3)
epic5 = create(:epic, group: group, parent: epic4) epic5 = create(:epic, group: group, parent: epic4)
epic6 = create(:epic, group: group, parent: epic5) epic.parent = epic5
epic.parent = epic6
expect(epic.valid_parent?).to be_falsey expect(epic.valid_parent?).to be_falsey
end end
...@@ -149,8 +148,7 @@ describe Epic do ...@@ -149,8 +148,7 @@ describe Epic do
it 'returns false when total depth after adding would exceed limit' do it 'returns false when total depth after adding would exceed limit' do
child_epic2 = create(:epic, group: group, parent: child_epic1) child_epic2 = create(:epic, group: group, parent: child_epic1)
child_epic3 = create(:epic, group: group, parent: child_epic2) child_epic3 = create(:epic, group: group, parent: child_epic2)
child_epic4 = create(:epic, group: group, parent: child_epic3) create(:epic, group: group, parent: child_epic3)
create(:epic, group: group, parent: child_epic4)
epic.parent = parent_epic epic.parent = parent_epic
......
...@@ -135,15 +135,32 @@ describe API::EpicLinks do ...@@ -135,15 +135,32 @@ describe API::EpicLinks do
end end
context 'when user is developer' do context 'when user is developer' do
it 'returns 201 status' do before do
group.add_developer(user) group.add_developer(user)
end
it 'returns 201 status' do
subject subject
expect(response).to have_gitlab_http_status(201) expect(response).to have_gitlab_http_status(201)
expect(response).to match_response_schema('public_api/v4/linked_epic', dir: 'ee') expect(response).to match_response_schema('public_api/v4/linked_epic', dir: 'ee')
expect(epic.reload.children).to include(Epic.last) expect(epic.reload.children).to include(Epic.last)
end end
context 'and epic has errors' do
it 'returns 400 error' do
child_epic = Epic.new(title: 'with errors')
errors = ActiveModel::Errors.new(child_epic).tap { |e| e.add(:parent_id, "error message") }
allow(child_epic).to receive(:errors).and_return(errors)
allow_next_instance_of(Epics::CreateService) do |service|
allow(service).to receive(:execute).and_return(child_epic)
end
subject
expect(response).to have_gitlab_http_status(400)
end
end
end 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