Enable hierachy restrictions for work item relationships
What does this MR do and why?
This MR sets cross_hierarchy_enabled
columns true for the following relationships:
Issue -> Task
Objective -> Objective
Objective -> Key Results
Incident -> Task
Ticket -> Task
Issue: #462219 (closed)
Database
Migration UP
bundle exec rails db:migrate:up:main VERSION=20240517061424
main: == [advisory_lock_connection] object_id: 124900, pg_backend_pid: 9274
main: == 20240517061424 EnableCrossHierarchyForHierarchyRestrictions: migrating =====
main: == 20240517061424 EnableCrossHierarchyForHierarchyRestrictions: migrated (0.0648s)
main: == [advisory_lock_connection] object_id: 124900, pg_backend_pid: 9274
Migration DOWN
bundle exec rails db:migrate:down:main VERSION=20240517061424
main: == [advisory_lock_connection] object_id: 124920, pg_backend_pid: 8639
main: == 20240517061424 EnableCrossHierarchyForHierarchyRestrictions: reverting =====
main: == 20240517061424 EnableCrossHierarchyForHierarchyRestrictions: reverted (0.0454s)
main: == [advisory_lock_connection] object_id: 124920, pg_backend_pid: 8639
How to set up and validate locally
- In
master
branch open rails console and enable work items at the group level withFeature.enable(:namespace_level_work_items)
- Login and visit
https://GDK_URL/-/graphql-explorer
to create 3 work items. One should have the typeKey Result
and two the typeObjective
. All items should be created in a different group. (NOTE: You should enable OKRs at all the three projects -Feature.enable(:okrs_mvc, Project.find(4)
before creating OKR records.
Use these mutations to create the above 3 records
# fetch WI type global ID for Objective and Key Result and replace <workItemTypeId> if different
query gettWorkItemTypes {
project(fullPath: "gitlab-org/gitlab-test") {
id
workItemTypes {
nodes {
id
name
}
}
}
}
# Create each work item and take note of the ID
mutation createObj {
workItemCreate(input: {namespacePath: "flightjs/Flight", title: "Work Item Type Obj", workItemTypeId: "gid://gitlab/WorkItems::Type/6"}) {
errors
workItem {
id
workItemType {
name
}
}
}
}
mutation createObj1 {
workItemCreate(input: {namespacePath: "gitlab-org/gitlab-shell", title: "Work Item Type Obj 1", workItemTypeId: "gid://gitlab/WorkItems::Type/6"}) {
errors
workItem {
id
workItemType {
name
}
}
}
}
mutation createKR {
workItemCreate(input: {namespacePath: "project_path", title: "Work Item Type KR, workItemTypeId: "gid://gitlab/WorkItems::Type/7"}) {
errors
workItem {
id
workItemType {
name
}
}
}
}
- Try to create the relationships and verify that an error is returned
mutations
mutation setKRParent {
workItemUpdate(input: {id: "gid://gitlab/WorkItem/<kr_id>", hierarchyWidget: { parentId: "gid://gitlab/WorkItem/<obj-id>" }}) {
errors
workItem {
widgets {
... on WorkItemWidgetHierarchy {
parent {
title
id
}
}
}
}
}
}
mutation setObjParent {
workItemUpdate(input: {id: "gid://gitlab/WorkItem/<obj-id>", hierarchyWidget: { parentId: "gid://gitlab/WorkItem/<obj-1-id>" }}) {
errors
workItem {
widgets {
... on WorkItemWidgetHierarchy {
parent {
title
id
}
}
}
}
}
}
Error
{
"data": {
"workItemUpdate": {
"errors": [
"#39 cannot be added: parent must be in the same project or group as child."
],
"workItem": null
}
}
}
-
Checkout this MR's branch
akotte/enable-cross-hierarchy
, run migrations and attempt to create the relationships using the same mutations as step3
. Verify that parents are set. -
Follow all the above steps to verify the
Issue -> Task
,Ticket -> Task
,Incident -> Task
relationships.
Edited by Abhilash Kotte