Skip to content

Fix create epic REST endpoints

Eugenia Grieff requested to merge fix-create-epic-endpoints into master

What does this MR do and why?

When creating an epic and assigning it to a parent using REST endpoints we are not checking that the licensed feature subepics is available or creating system notes for the relation.

Currently, these endpoints send the param parent_id to Epics::CreateService that creates the epic with this attribute.

This MR changes the param to parent to make use of the existing functionality in Epics::BaseService#assign_parent_epic_for that sets the parent using Epics::EpicLinks::CreateService instead of the attribute.

Using the EpicLinks service is preferable because it handles permissions and validations as well as creating system notes for both epics.

How to set up and validate locally

  1. Given a group Test Group with an existing epic (iid: 1) create a new child epic using the epic links endpoint:
    export GITLAB_PAT=<your api token>
    curl -X POST -H "Authorization: Bearer $GITLAB_PAT" -d title=new_child_epic http://gdk.test:3000/api/v4/groups/test-group/epics/1/epics
  2. In rails console check the latest epic's notes
    child_epic = Epic.last
    child_epic.notes.last.note
    => "added epic &1 as parent epic"
    
    child_epic.parent.notes.last.note
    => "added epic &2 as child epic"
  3. Create a new child epic using the epics endpoint:
    curl -X POST -H "Authorization: Bearer $GITLAB_PAT" -d title=new_epic -d parent_id=1 http://gdk.test:3000/api/v4/groups/test-group/epics
  4. In rails console check the latest epic's notes
    child_epic = Epic.last
    child_epic.notes.last.note
    => "added epic &1 as parent epic"
    
    child_epic.parent.notes.last.note
    => "added epic &3 as child epic"

The epics endpoint is used in the epic's page so it can be tested there too:

  1. Visit http://gdk.test:3000/groups/test-group/-/epics/1
  2. Add a new child epic using the children widget
  3. Screenshot_2022-11-16_at_15.19.47
  4. New system notes should be created.
  5. Screenshot_2022-11-16_at_15.23.41

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugenia Grieff

Merge request reports