Skip to content

Add GraphQL mutation to unlink work items

Related to #416787 (closed)

What does this MR do and why?

Following !127380 (merged) that added a mutation to link work items, this MR adds the mutation WorkItemRemoveLinkedItems to unlink them.

The mutation accepts a work item ID and a collection of IDs to be unlinked. If all ids fail to be removed the request fails and the errors are included in the response's errors field. If only some ids fail, the request succeeds and the failed ids are included as part of the response's message field. Reasons to fail:

  1. The work item with the given ID is not found
  2. The user has insufficient permissions to unlink the work item (at least Guest role access for the work item's project)

This mutation is marked as alpha and guarded by the feature flag linked_work_tems, disabled by default.

I've included notes inline to explain specific changes.

Screenshots or screen recordings

This MR doesn't include UI changes

Screen_Recording_2023-08-15_at_15.11.35

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Enable feature flag
Feature.enable(:linked_work_items)
  1. In rails console create 3 tasks and take notes of their ID
author, project = User.first, Project.first
wi_type = WorkItems::Type.find_by(base_type: 'task')
task1 = WorkItem.create!(title: "Source Task", project: project, author: author, work_item_type: wi_type)
task2 = WorkItem.create!(title: "Source Task", project: project, author: author, work_item_type: wi_type)
task3 = WorkItem.create!(title: "Source Task", project: project, author: author, work_item_type: wi_type)
  1. Visit https://gdk.test:3000/-/graphql-explorer and link tasks 2 and 3 to task 1 using the following mutation
linkItems
mutation linkItems {
  workItemAddLinkedItems(
    input: {
      id: "gid://gitlab/WorkItem/<ID1>",
      workItemsIds: ["gid://gitlab/WorkItem/<ID2>", "gid://gitlab/WorkItem/<ID3>"]
    }
  ) {
    errors
    message
  }
}
  1. Verify that items have been linked by querying the work item's WorkItemWidgetLinkedItems widget
getLinkedITems
query getLinkedITems {
  workItem(id: "gid://gitlab/WorkItem/<ID1>") {
    widgets {
      ...on WorkItemWidgetLinkedItems {
        linkedItems {
          edges {
            node {
              workItem {
                id
              }
            }
          }
        }
      }
    }
  }
}
  1. Use the new mutation to unlink the items
unlinkItems
mutation unlinkItems {
  workItemRemoveLinkedItems(
    input: {
      id: "gid://gitlab/WorkItem/<ID1>",
      workItemsIds: ["gid://gitlab/WorkItem/<ID2>", "gid://gitlab/WorkItem/<ID3>"]
    }
  ) {
    errors
    message
  }
}
  1. Verify that items have been unlinked using the query from step 4

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