Skip to content
Snippets Groups Projects
Commit 42a80c55 authored by Eugenia Grieff's avatar Eugenia Grieff :two:
Browse files

Fix create epic REST endpoints

When creating an epic and assigning it to a parent
using REST endpoints check that the licensed feature
subepics is available and create system notes for the relation

Changelog: fixed
EE: true
parent 9e9c845f
No related branches found
No related tags found
1 merge request!107736Create system notes when creating epic with parent
......@@ -14,6 +14,12 @@ def execute
create(epic)
end
def handle_changes(epic, options)
super
handle_parent_change(epic)
end
private
def before_create(epic)
......@@ -40,5 +46,11 @@ def set_date_params
params[:end_date] = params[:due_date_fixed]
end
end
def handle_parent_change(epic)
return unless epic.parent
SystemNoteService.change_epics_relation(epic.parent, epic, current_user, 'relate_epic')
end
end
end
......@@ -216,9 +216,12 @@ def get_epics
it 'returns 201 status' do
subject
child_epic = Epic.last
expect(response).to have_gitlab_http_status(:created)
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(child_epic)
expect(epic.notes.last&.note).to eq("added epic #{child_epic.to_reference} as child epic")
expect(child_epic.notes.last&.note).to eq("added epic #{epic.to_reference} as parent epic")
end
context 'when the parent epic is confidential' do
......
......@@ -5,7 +5,7 @@
RSpec.describe API::Epics, feature_category: :portfolio_management do
let_it_be(:user) { create(:user) }
let(:group) { create(:group) }
let_it_be(:group, reload: true) { create(:group) }
let(:project) { create(:project, :public, group: group) }
let(:label) { create(:group_label, group: group) }
let(:label2) { create(:group_label, group: group, title: 'label-2') }
......@@ -159,8 +159,8 @@
end
context 'with a parent epic' do
let!(:epic) { create(:epic, group: group) }
let!(:epic2) { create(:epic, group: group, parent_id: epic.id) }
let_it_be(:epic) { create(:epic, group: group) }
let_it_be(:epic2) { create(:epic, group: group, parent_id: epic.id) }
before do
stub_licensed_features(epics: true)
......@@ -651,7 +651,7 @@
describe 'POST /groups/:id/epics' do
let(:url) { "/groups/#{group.path}/epics" }
let(:parent_epic) { create(:epic, group: group) }
let_it_be(:parent_epic) { create(:epic, group: group) }
let(:params) do
{
title: 'new epic',
......@@ -668,7 +668,7 @@
context 'when epics feature is enabled' do
before do
stub_licensed_features(epics: true)
stub_licensed_features(epics: true, subepics: true)
group.add_developer(user)
end
......@@ -701,6 +701,15 @@
expect(json_response['_links']['parent']).to end_with("/api/v4/groups/#{parent_epic.group.id}/epics/#{parent_epic.iid}")
end
it 'create system notes for new relation' do
post api(url, user), params: params
new_epic = Epic.last
expect(parent_epic.notes.last&.note).to eq("added epic #{new_epic.to_reference} as child epic")
expect(new_epic.notes.last&.note).to eq("added epic #{parent_epic.to_reference} as parent epic")
end
it 'creates a new epic' do
epic = Epic.last
......@@ -775,6 +784,25 @@
expect(result.due_date_fixed).to eq(due_date)
end
end
context 'when parent epic is invalid' do
let_it_be(:confidential_parent) { create(:epic, group: group, confidential: true) }
let(:params) do
{
title: 'new epic',
description: 'epic description',
parent_id: confidential_parent.id,
confidential: false
}
end
it 'returns 400' do
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']['confidential'])
.to include('A non-confidential epic cannot be assigned to a confidential parent epic')
end
end
end
context 'with rate limiter', :freeze_time, :clean_gitlab_redis_rate_limiting do
......
......@@ -41,6 +41,30 @@
expect(NewEpicWorker).to have_received(:perform_async).with(epic.id, user.id)
end
context 'handling parent change' do
context 'when parent is set' do
it 'creates system notes' do
subject
epic = Epic.last
expect(epic.parent).to eq(parent_epic)
expect(epic.notes.last.note).to eq("added epic #{parent_epic.to_reference} as parent epic")
expect(parent_epic.notes.last.note).to eq("added epic #{epic.to_reference} as child epic")
end
end
context 'when parent is not set' do
it 'does not create system notes' do
params[:parent_id] = nil
subject
epic = Epic.last
expect(epic.parent).to be_nil
expect(epic.notes).to be_empty
end
end
end
context 'handling fixed dates' do
it 'sets the fixed date correctly' do
date = Date.new(2019, 10, 10)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment