Commit 445cb461 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'issue_38331' into 'master'

Do not allow to create epic when parent reached hierarchy limit

See merge request gitlab-org/gitlab!22729
parents 9d0092ea 8cc4716d
......@@ -362,7 +362,7 @@ module EE
private :validate_parent
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
private :level_depth_exceeded?
......@@ -371,6 +371,5 @@ module EE
hierarchy.base_and_ancestors(hierarchy_order: :asc)
end
private :base_and_ancestors
end
end
---
title: Fix child epics depth validation
merge_request: 22729
author:
type: fixed
......@@ -84,7 +84,7 @@ module API
if child_epic.valid?
present child_epic, with: EE::API::Entities::LinkedEpic, user: current_user
else
render_validation_error!(epic)
render_validation_error!(child_epic)
end
end
......
......@@ -128,8 +128,7 @@ describe Epic do
epic3 = create(:epic, group: group, parent: epic2)
epic4 = create(:epic, group: group, parent: epic3)
epic5 = create(:epic, group: group, parent: epic4)
epic6 = create(:epic, group: group, parent: epic5)
epic.parent = epic6
epic.parent = epic5
expect(epic.valid_parent?).to be_falsey
end
......@@ -149,8 +148,7 @@ describe Epic do
it 'returns false when total depth after adding would exceed limit' do
child_epic2 = create(:epic, group: group, parent: child_epic1)
child_epic3 = create(:epic, group: group, parent: child_epic2)
child_epic4 = create(:epic, group: group, parent: child_epic3)
create(:epic, group: group, parent: child_epic4)
create(:epic, group: group, parent: child_epic3)
epic.parent = parent_epic
......
......@@ -135,15 +135,32 @@ describe API::EpicLinks do
end
context 'when user is developer' do
it 'returns 201 status' do
before do
group.add_developer(user)
end
it 'returns 201 status' do
subject
expect(response).to have_gitlab_http_status(201)
expect(response).to match_response_schema('public_api/v4/linked_epic', dir: 'ee')
expect(epic.reload.children).to include(Epic.last)
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
......
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