Add ability to define work item links restrictions
Similarly to the existing restrictions that apply to parent-child relationships, we need a way to define limitations for linking work items.
The required restrictions are specified in: &6286
Proposal
-
Add a new table
work_item_related_link_restrictions
for storing the restrictions. The table would include the columnssource_type_id
,target_type_id
andlink_type
.An example case where the work item type ID for Issue is
1
and2
for the *Epic type:id
source_type_id
target_type_id
link_type
1 1 1 0 2 2 2 0 3 1 2 0 4 2 1 0 5 1 2 1 - In the first 2 rows we specify that issues can be related to issues and epics can be related to epics.
- In rows
3
and4
we specify that issues can relate to epics and epics can relate to issues. In the case of arelates_to
link, we could use it as a single entry because the direction of the link is not relevant, but would mean adding an extra query in the validation to find restrictions for the source and the target. - In row
5
we specify that issues can block epics. Given that an entry for the opposite direction is missing, epics are not allowed to block issues in this scenario.
-
Add model validation
After the table was added the model
WorkItems::RelatedWorkItemLink
should include a validation that checks if a restriction is present for the link that's being created.Example:
def validate_related_link_restrictions return unless source && target restriction = ::WorkItems::RelatedLinkRestriction.find_by_source_type_id_and_target_type_id_and_link_type( source.work_item_type_id, target.work_item_type_id, link_type ) return if restriction errors.add :source, s_('is not allowed to be linked to this type of item') end
-
Add default restrictions
Use migration to add default restrictions and an importer similar to
HierarchyRestrictionsImporter
so they can be included when seeding DB.
Tasks
-
Add DB table to store restrictions [!133044 (merged)] -
Add data migration for restrictions matching the tables in &6286 [!133452 (merged)] -
Add validation to WorkItems::RelatedWorkItemLink
to prevent creating unsupported links [!133618 (merged)]