Skip to content

Enable hierachy restrictions for work item relationships

Abhilash Kotte requested to merge akotte/enable-cross-hierarchy into master

What does this MR do and why?

This MR sets cross_hierarchy_enabled columns true for the following relationships:

  1. Issue -> Task
  2. Objective -> Objective
  3. Objective -> Key Results
  4. Incident -> Task
  5. Ticket -> Task

Issue: #462219

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

  1. In master branch open rails console and enable work items at the group level with Feature.enable(:namespace_level_work_items)
  2. Login and visit https://GDK_URL/-/graphql-explorer to create 3 work items. One should have the type Key Result and two the type Objective. 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
      }
    }
  }
}
  1. 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
    }
  }
}
  1. Checkout this MR's branch akotte/enable-cross-hierarchy, run migrations and attempt to create the relationships using the same mutations as step 3. Verify that parents are set.

  2. Follow all the above steps to verify the Issue -> Task, Ticket -> Task, Incident -> Task relationships.

Edited by Abhilash Kotte

Merge request reports