Skip to content

Add validation for legacy epic issue relation

What does this MR do and why?

Related to #423980 (closed)

With the introduction of the work item type Epic it's necessary to have a validation preventing an issue from having a legacy epic and work item epic assigned at the same time.

Screenshots or screen recordings

No UI changes

How to set up and validate locally

  1. Using the Rails console create an issue with a legacy epic assigned to it:
user = User.first
group = Group.create!(name: 'Test Group', path: 'test-group3')
project = Project.create!(title: 'Test Project', path: 'test-project3', namespace: group, creator: user)
legacy_issue1 = Issue.create!(title: "Legacy Issue 1", project: project, author: user)
legacy_epic = Epic.create!(title: 'Legacy Epic', author: user, group: group)
EpicIssue.create!(epic: legacy_epic, issue: legacy_issue1)
  1. Also create a work item with the type Epic
epic_type = WorkItems::Type.find_by(base_type: 'epic')
work_item_epic = WorkItem.create!(title: "Work Item Epic", project: project, author: user, work_item_type: epic_type)
  1. Attempt to set the work item epic as a parent of the issue using GraphQL by visiting https://GDK_URL/-/graphql-explorer and running the following mutation (replace ruby expressions marked with <> with their result)
mutation workItemUpdate { 
  workItemUpdate(input: {id: "gid://gitlab/WorkItem/<legacy_issue1.id>", hierarchyWidget: { parentId: "gid://gitlab/WorkItem/<work_item_epic.id>"}}) {
    errors
  }
}
  1. Verify that the response includes the error already assigned to an epic
  2. Back in the console create another issue, this time with a parent work item already assigned to it:
legacy_issue2 = Issue.create!(title: "Legacy Issue 2", project: project, author: user)
WorkItems::ParentLink.create!(work_item_id: legacy_issue2.id, work_item_parent: work_item_epic)
  1. Run a GraphQL mutation to set a legacy epic
mutation setLegacyEpic {
  issueSetEpic(input: {projectPath: <project.full_path>, iid: "<legacy_issue2.iid>", epicId: "gid://gitlab/Epic/<legacy_epic.id>"}) {
    errors
  }
}
  1. Verify that the response includes the error already assigned to an epic

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

Loading