Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Refer to a work package by a reference for seeding

Christophe Bliard90d67fdcb873
diff --git a/app/seeders/demo_data/references.rb b/app/seeders/demo_data/references.rb
index 3269f9c59ee..605a653cf3b 100644
--- a/app/seeders/demo_data/references.rb
+++ b/app/seeders/demo_data/references.rb
@@ -96,12 +96,13 @@ module DemoData
)
end
- ##
- # Turns `##wp:"Some subject"` into
- # `/projects/demo-project/work_packages/42/activity` given there is a work package
- # named "Some subject" (its subject here being "Some subject").
+ ## Turns `##wp:"Some subject"` or `##wp:some_subject` into
+ # `/projects/demo-project/work_packages/42/activity` given there is a work
+ # package named "Some subject" (its subject here being "Some subject") or
+ # referenced with :some_subject.
#
- # Alternatively `##wp.id:"Some subject"` is translated into just the ID.`
+ # Alternatively `##wp.id:"Some subject"` or `##wp.id:some_subject` is
+ # translated into just the ID.`
def link_work_packages(str, project)
link_reference(
str,
@@ -126,22 +127,35 @@ module DemoData
end
def link_reference(str, model:, find_by:, project:, link:, tag: nil)
- return str unless str.present?
+ return str if str.blank?
tag ||= model.name.downcase
- str.gsub(/###{tag}(\.id)?:"[^"]+"/) do |match|
- identifier = match.split(":", 2).last[1..-2] # strip quotes of part behind :
- instance = model.where(find_by => identifier, :project => project).first!
-
- if match.include?(".id")
- instance.id
- else
- link.call instance
+ [
+ [/###{tag}(\.id)?:"[^"]+"/, ->(match) { find_instance_by_query(match, model:, find_by:, project:) }],
+ [/###{tag}(\.id)?:[a-z_0-9]+/, ->(match) { find_instance_by_reference(match) }]
+ ].reduce(str) do |str_acc, (regex, find_instance)|
+ str_acc.gsub(regex) do |match|
+ instance = find_instance.(match)
+ if match.include?(".id")
+ instance.id
+ else
+ link.call instance
+ end
end
end
end
+ def find_instance_by_query(text, model:, find_by:, project:)
+ identifier = text.split(":", 2).last[1..-2] # strip quotes of part behind :
+ model.where(find_by => identifier, :project => project).first!
+ end
+
+ def find_instance_by_reference(text)
+ reference = text.split(":", 2).last.to_sym
+ seed_data.find_reference(reference)
+ end
+
def query_link(query)
path = url_helpers.project_work_packages_path project_id: query.project.identifier
diff --git a/app/seeders/demo_data/work_package_seeder.rb b/app/seeders/demo_data/work_package_seeder.rb
index 97315b3ad3e..6f55a0fb0f7 100644
--- a/app/seeders/demo_data/work_package_seeder.rb
+++ b/app/seeders/demo_data/work_package_seeder.rb
@@ -26,13 +26,13 @@
# See COPYRIGHT and LICENSE files for more details.
module DemoData
class WorkPackageSeeder < Seeder
- attr_reader :project, :statuses, :repository,
- :types, :project_data
+ attr_reader :project, :statuses, :repository, :types
+ alias_method :project_data, :seed_data
include ::DemoData::References
def initialize(project, project_data)
- super()
+ super(project_data)
@project = project
@project_data = project_data
@statuses = Status.all
@@ -51,7 +51,8 @@ module DemoData
def seed_demo_work_packages
project_data.each('work_packages') do |attributes|
- create_or_update_work_package(attributes)
+ work_package = create_or_update_work_package(attributes)
+ memorize_work_package(work_package, attributes)
end
end
@@ -91,6 +92,7 @@ module DemoData
child.parent = work_package
child.save!
+ memorize_work_package(child, child_attributes)
end
end
@@ -104,10 +106,26 @@ module DemoData
status: find_status(attributes),
type: find_type(attributes),
priority: find_priority(attributes) || IssuePriority.default,
- parent: WorkPackage.find_by(subject: attributes['parent'])
+ parent: find_work_package(attributes['parent'])
}
end
+ def memorize_work_package(work_package, attributes)
+ project_data.store_reference(attributes['reference'], work_package)
+ attributes['work_package'] = work_package
+ end
+
+ def find_work_package(subject_or_reference)
+ case subject_or_reference
+ when String
+ subject = subject_or_reference
+ WorkPackage.find_by(subject:)
+ when Symbol
+ reference = subject_or_reference
+ seed_data.find_reference(reference)
+ end
+ end
+
def find_principal(name)
if name
group_assignee = Group.find_by(lastname: name)
@@ -174,9 +192,8 @@ module DemoData
def create_relations(attributes)
Array(attributes['relations']).each do |relation|
- root_work_package = WorkPackage.find_by!(subject: attributes['subject'])
- to_work_package = WorkPackage.find_by(subject: relation['to'], project: root_work_package.project)
- to_work_package ||= WorkPackage.find_by!(subject: relation['to'])
+ root_work_package = attributes['work_package'] # memorized on creation
+ to_work_package = find_work_package(relation['to'])
create_relation(
to: to_work_package,
from: root_work_package,
diff --git a/app/seeders/seed_data.rb b/app/seeders/seed_data.rb
index 082679fb692..30eea908b93 100644
--- a/app/seeders/seed_data.rb
+++ b/app/seeders/seed_data.rb
@@ -29,14 +29,25 @@
#++
class SeedData
- def initialize(data)
+ def initialize(data, registry = nil)
@data = data
+ @registry = registry || {}
+ end
+
+ def store_reference(reference, record)
+ return if reference.nil?
+
+ registry[reference] = record
+ end
+
+ def find_reference(reference)
+ registry.fetch(reference) { raise ArgumentError, "Nothing registered with reference #{reference.inspect}" }
end
def lookup(path)
case sub_data = fetch(path)
when Hash
- SeedData.new(sub_data)
+ SeedData.new(sub_data, registry)
else
sub_data
end
@@ -58,12 +69,14 @@ class SeedData
return if sub_data.nil?
sub_data.each_value do |item_data|
- yield SeedData.new(item_data)
+ yield SeedData.new(item_data, registry)
end
end
private
+ attr_reader :registry
+
def fetch(path)
keys = path.to_s.split('.')
@data.dig(*keys)
diff --git a/app/seeders/standard.yml b/app/seeders/standard.yml
index 71c97a7d55c..18f7dc69695 100644
--- a/app/seeders/standard.yml
+++ b/app/seeders/standard.yml
@@ -149,7 +149,7 @@ projects:
3. *Create a new work package*: &rightarrow; Go to [Work packages &rightarrow; Create]({{opSetting:base_url}}/projects/demo-project/work_packages/new).
4. *Create and update a project plan*: &rightarrow; Go to [Project plan]({{opSetting:base_url}}/projects/demo-project/work_packages?query_id=##query.id:"Project plan") in the project navigation.
5. *Activate further modules*: &rightarrow; Go to [Project settings &rightarrow; Modules]({{opSetting:base_url}}/projects/demo-project/settings/modules).
- 6. *Complete your tasks in the project*: &rightarrow; Go to [Work packages &rightarrow; Tasks]({{opSetting:base_url}}/projects/demo-project/work_packages/details/##wp.id:"Set date and location of conference"/overview?query_id=##query.id:"Tasks").
+ 6. *Complete your tasks in the project*: &rightarrow; Go to [Work packages &rightarrow; Tasks]({{opSetting:base_url}}/projects/demo-project/work_packages/details/##wp.id:set_date_and_location_of_conference/overview?query_id=##query.id:"Tasks").
Here you will find our [User Guides](https://www.openproject.org/docs/user-guide/).
Please let us know if you have any questions or need support. Contact us: [support[at]openproject.com](mailto:[email protected]).
@@ -206,6 +206,7 @@ projects:
children:
- start: 0
t_subject: Set date and location of conference
+ reference: :set_date_and_location_of_conference
description: ''
status: default_status_in_progress
type: default_type_task
@@ -237,8 +238,7 @@ projects:
type: default_type_task
duration: 1
relations:
- # TODO: ref wont be found with another language
- - to: Set date and location of conference
+ - to: :set_date_and_location_of_conference
type: follows
schedule_manually: false
- start: 4
@@ -248,8 +248,7 @@ projects:
type: default_type_task
duration: 11
relations:
- # TODO: ref wont be found with another language
- - to: Set date and location of conference
+ - to: :set_date_and_location_of_conference
type: follows
schedule_manually: false
duration: 15
diff --git a/modules/bim/app/seeders/bim.yml b/modules/bim/app/seeders/bim.yml
index 9c02027ead4..888f0b1d47a 100644
--- a/modules/bim/app/seeders/bim.yml
+++ b/modules/bim/app/seeders/bim.yml
@@ -359,6 +359,7 @@ projects:
work_packages:
- :start: 4
:t_subject: Project kick off construction project
+ :reference: :project_kick_off_construction_project
:t_description: |-
The project kick off initializes the start of the project in your company. Everybody being part of this project should be invited to the kick off for a first briefing.
@@ -377,6 +378,7 @@ projects:
:children:
- :start: 7
:t_subject: Gathering first project information
+ :reference: :gathering_first_project_information
:t_description: |-
## Goal
@@ -395,6 +397,7 @@ projects:
:duration: 4
- :start: 14
:t_subject: Summarize the results
+ :reference: :summarize_the_results
:t_description: |-
## Goal
@@ -414,11 +417,11 @@ projects:
:assigned_to: Planners
:duration: 4
:relations:
- # TODO: ref wont be found with another language
- - :to: Gathering first project information
+ - :to: :gathering_first_project_information
:type: follows
- :start: 21
:t_subject: End of basic evaluation
+ :reference: :end_of_basic_evaluation
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -427,14 +430,12 @@ projects:
:assigned_to: Planners
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Summarize the results
+ - :to: :summarize_the_results
:type: follows
:assigned_to: Planners
:duration: 14
:relations:
- # TODO: ref wont be found with another language
- - :to: Project kick off construction project
+ - :to: :project_kick_off_construction_project
:type: follows
- :start: 22
:t_subject: Preliminary planning
@@ -445,6 +446,7 @@ projects:
:children:
- :start: 22
:t_subject: Developing first draft
+ :reference: :developing_first_draft
:t_description: |-
## Goal
@@ -464,11 +466,11 @@ projects:
:assigned_to: Planners
:duration: 10
:relations:
- # TODO: ref wont be found with another language
- - :to: End of basic evaluation
+ - :to: :end_of_basic_evaluation
:type: follows
- :start: 35
:t_subject: Summarize results
+ :reference: :summarize_results
:t_description: |-
## Goal
@@ -488,13 +490,13 @@ projects:
:assigned_to: Planners
:duration: 4
:relations:
- # TODO: ref wont be found with another language
- - :to: Developing first draft
+ - :to: :developing_first_draft
:type: follows
:assigned_to: Planners
:duration: 17
- :start: 42
:t_subject: Passing of preliminary planning
+ :reference: :passing_of_preliminary_planning
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -503,8 +505,7 @@ projects:
:assigned_to: Planners
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Summarize results
+ - :to: :summarize_results
:type: follows
- :start: 44
:t_subject: Design planning
@@ -515,6 +516,7 @@ projects:
:children:
- :start: 44
:t_subject: Finishing design
+ :reference: :finishing_design
:t_description: |-
## Goal
@@ -533,11 +535,11 @@ projects:
:assigned_to: Planners
:duration: 45
:relations:
- # TODO: ref wont be found with another language
- - :to: Passing of preliminary planning
+ - :to: :passing_of_preliminary_planning
:type: follows
- :start: 90
:t_subject: Design freeze
+ :reference: :design_freeze
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -546,8 +548,7 @@ projects:
:assigned_to: Planners
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Finishing design
+ - :to: :finishing_design
:type: follows
# TODO: ref wont be found with another language
:assigned_to: Planners
@@ -560,6 +561,7 @@ projects:
:children:
- :start: 98
:t_subject: Start constructing
+ :reference: :start_constructing
:t_description: |-
## Goal
@@ -596,8 +598,7 @@ projects:
:assigned_to: Planners
:duration: 25
:relations:
- # TODO: ref wont be found with another language
- - :to: Start constructing
+ - :to: :start_constructing
:type: follows
- :start: 149
:t_subject: Building construction
@@ -658,6 +659,7 @@ projects:
:duration: 25
- :start: 189
:t_subject: Final touches
+ :reference: :final_touches
:t_description: |-
## Goal
@@ -692,14 +694,13 @@ projects:
:type: default_type_milestone
:duration: 1
:relations:
- - :to: Final touches
+ - :to: :final_touches
:type: follows
# TODO: ref wont be found with another language
:assigned_to: Planners
:duration: 110
:relations:
- # TODO: ref wont be found with another language
- - :to: Design freeze
+ - :to: :design_freeze
:type: follows
demo-bim-project:
t_name: (Demo) BIM project
@@ -845,6 +846,7 @@ projects:
work_packages:
- :start: 14
:t_subject: Project kick off creating BIM model
+ :reference: :project_kick_off_creating_bim_model
:t_description: |-
The project Kickoff initializes the start of the project in your company. The whole project team should be invited to the Kickoff for a first briefing.
@@ -856,6 +858,7 @@ projects:
:duration: 1
- :start: 15
:t_subject: Project preparation
+ :reference: :project_preparation
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -863,6 +866,7 @@ projects:
:children:
- :start: 15
:t_subject: Gathering the project specific data and information for the BIM model
+ :reference: :gathering_project_data_and_info
:t_description: |-
## Goal
@@ -883,10 +887,11 @@ projects:
:assigned_to: Planners
:duration: 14
:relations:
- - :to: Project kick off creating BIM model
+ - :to: :project_kick_off_creating_bim_model
:type: follows
- :start: 33
:t_subject: Creating the BIM execution plan
+ :reference: :creating_bim_execution_plan
:t_description: |-
# Goal
@@ -903,10 +908,11 @@ projects:
:assigned_to: Lead BIM Coordinators
:duration: 18
:relations:
- - :to: Gathering the project specific data and information for the BIM model
+ - :to: :gathering_project_data_and_info
:type: follows
- :start: 52
:t_subject: Completion of the BIM execution plan
+ :reference: :completion_of_bim_execution_plan
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: bim.default_status_resolved
@@ -914,13 +920,14 @@ projects:
:assigned_to: BIM Coordinators
:duration: 1
:relations:
- - :to: Creating the BIM execution plan
+ - :to: :creating_bim_execution_plan
:type: follows
# TODO: ref wont be found with another language
:assigned_to: BIM Managers
:duration: 37
- :start: 53
:t_subject: End of preparation phase
+ :reference: :end_of_preparation_phase
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -929,7 +936,7 @@ projects:
:assigned_to: BIM Managers
:duration: 1
:relations:
- - :to: Project preparation
+ - :to: :project_preparation
:type: follows
- :start: 54
:t_subject: Creating initial BIM model
@@ -940,6 +947,7 @@ projects:
:children:
- :start: 54
:t_subject: Modelling initial BIM model
+ :reference: :modelling_initial_bim_model
:t_description: |-
# Goal
@@ -957,11 +965,11 @@ projects:
:assigned_to: BIM Modellers
:duration: 7
:relations:
- # TODO: ref wont be found with another language
- - :to: End of preparation phase
+ - :to: :end_of_preparation_phase
:type: follows
- :start: 62
:t_subject: Initial, internal model check and revising
+ :reference: :initial_internal_model_check_and_revising
:t_description: |-
# Goal
@@ -977,11 +985,11 @@ projects:
:assigned_to: Lead BIM Coordinators
:duration: 2
:relations:
- # TODO: ref wont be found with another language
- - :to: Modelling initial BIM model
+ - :to: :modelling_initial_bim_model
:type: follows
- :start: 65
:t_subject: Submitting initial BIM model
+ :reference: :submitting_initial_bim_model
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -990,15 +998,13 @@ projects:
:assigned_to: BIM Modellers
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Initial, internal model check and revising
+ - :to: :initial_internal_model_check_and_revising
:type: follows
# TODO: ref wont be found with another language
:assigned_to: Architects
:duration: 11
:relations:
- # TODO: ref wont be found with another language
- - :to: Completion of the BIM execution plan
+ - :to: :completion_of_bim_execution_plan
:type: follows
- :start: 66
:t_subject: Modelling, first cycle
@@ -1009,6 +1015,7 @@ projects:
:children:
- :start: 66
:t_subject: Referencing external BIM models
+ :reference: :referencing_external_bim_models
:t_description: |-
# Goal
@@ -1025,11 +1032,11 @@ projects:
:assigned_to: BIM Modellers
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Submitting initial BIM model
+ - :to: :submitting_initial_bim_model
:type: follows
- :start: 67
:t_subject: Modelling the BIM model
+ :reference: :modelling_of_the_bim_model
:t_description: |-
# Goal
@@ -1046,11 +1053,11 @@ projects:
:assigned_to: BIM Modellers
:duration: 6
:relations:
- # TODO: ref wont be found with another language
- - :to: Referencing external BIM models
+ - :to: :referencing_external_bim_models
:type: follows
- :start: 74
:t_subject: First Cycle, internal model check and revising
+ :reference: :first_cycle_internal_model_check_and_revising
:t_description: |-
# Goal
@@ -1065,10 +1072,11 @@ projects:
:assigned_to: BIM Coordinators
:duration: 1
:relations:
- - :to: Modelling the BIM model
+ - :to: :modelling_of_the_bim_model
:type: follows
- :start: 76
:t_subject: Submitting BIM model
+ :reference: :submitting_bim_model
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -1077,15 +1085,13 @@ projects:
:assigned_to: BIM Modellers
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: First Cycle, internal model check and revising
+ - :to: :first_cycle_internal_model_check_and_revising
:type: follows
# TODO: ref wont be found with another language
:assigned_to: BIM Coordinators
:duration: 10
:relations:
- # TODO: ref wont be found with another language
- - :to: Submitting initial BIM model
+ - :to: :submitting_initial_bim_model
:type: follows
- :start: 77
:t_subject: Coordination, first cycle
@@ -1114,6 +1120,7 @@ projects:
:duration: 3
- :start: 77
:t_subject: Issue management, first cycle
+ :reference: :issue_management_first_cycle
:description: ''
:status: default_status_new
:type: default_type_phase
@@ -1122,6 +1129,7 @@ projects:
:duration: 4
- :start: 82
:t_subject: Finishing coordination, first cycle
+ :reference: :finishing_coordination_first_cycle
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -1130,18 +1138,17 @@ projects:
:assigned_to: Lead BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Issue management, first cycle
+ - :to: :issue_management_first_cycle
:type: follows
# TODO: ref wont be found with another language
:assigned_to: Lead BIM Coordinators
:duration: 5
:relations:
- # TODO: ref wont be found with another language
- - :to: Submitting BIM model
+ - :to: :submitting_bim_model
:type: follows
- :start: 83
:t_subject: Modelling & coordinating, second cycle
+ :reference: :modelling_and_coordinating_second_cycle
:t_description: "## Goal\r\n\r\n* ...\r\n\r\n## Description\r\n\r\n* ..."
:status: default_status_new
:type: default_type_phase
@@ -1149,11 +1156,11 @@ projects:
:assigned_to: Lead BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Finishing coordination, first cycle
+ - :to: :finishing_coordination_first_cycle
:type: follows
- :start: 84
:t_subject: Modelling & coordinating, ... cycle
+ :reference: :modelling_and_coordinating_another_cycle
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -1162,11 +1169,11 @@ projects:
:assigned_to: Lead BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Modelling & coordinating, second cycle
+ - :to: :modelling_and_coordinating_second_cycle
:type: follows
- :start: 85
:t_subject: Modelling & coordinating, (n-th minus 1) cycle
+ :reference: :modelling_and_coordinating_penultimate_cycle
:t_description: "## Goal\r\n\r\n* ...\r\n\r\n## Description\r\n\r\n* ..."
:status: default_status_new
:type: default_type_phase
@@ -1174,11 +1181,11 @@ projects:
:assigned_to: Lead BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Modelling & coordinating, ... cycle
+ - :to: :modelling_and_coordinating_another_cycle
:type: follows
- :start: 86
:t_subject: Modelling & coordinating n-th cycle
+ :reference: :modelling_and_coordinating_last_cycle
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -1187,11 +1194,11 @@ projects:
:assigned_to: BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Modelling & coordinating, (n-th minus 1) cycle
+ - :to: :modelling_and_coordinating_penultimate_cycle
:type: follows
- :start: 87
:t_subject: Finishing modelling & coordinating, n-th cycle
+ :reference: :finishing_modelling_and_coordinating
:t_description: This type is hierarchically a parent of the types &quot;Clash&quot;
and &quot;Request&quot;, thus represents a general note.
:status: default_status_new
@@ -1200,8 +1207,7 @@ projects:
:assigned_to: BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Modelling & coordinating n-th cycle
+ - :to: :modelling_and_coordinating_last_cycle
:type: follows
- :start: 88
:t_subject: Use model for construction phase
@@ -1230,6 +1236,7 @@ projects:
:duration: 5
- :start: 98
:t_subject: Construct the building
+ :reference: :construct_building
:t_description: |-
## Goal
@@ -1248,6 +1255,7 @@ projects:
:duration: 101
- :start: 200
:t_subject: Finish construction
+ :reference: :finish_construction
:description: ''
:status: default_status_new
:type: default_type_milestone
@@ -1255,18 +1263,17 @@ projects:
:assigned_to: BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Construct the building
+ - :to: :construct_building
:type: follows
# TODO: ref wont be found with another language
:assigned_to: BIM Coordinators
:duration: 112
:relations:
- # TODO: ref wont be found with another language
- - :to: Finishing modelling & coordinating, n-th cycle
+ - :to: :finishing_modelling_and_coordinating
:type: follows
- :start: 98
:t_subject: Issue management, construction phase
+ :reference: :issue_management_construction_phase
:description: ''
:status: default_status_new
:type: default_type_phase
@@ -1275,6 +1282,7 @@ projects:
:duration: 88
- :start: 210
:t_subject: Handover for Facility Management
+ :reference: :handover_for_facility_management
:t_description: |-
## Goal
@@ -1293,8 +1301,7 @@ projects:
:assigned_to: Lead BIM Coordinators
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Finish construction
+ - :to: :finish_construction
:type: follows
- :start: 211
:t_subject: Asset Management
@@ -1303,8 +1310,7 @@ projects:
:type: default_type_phase
:duration: 1
:relations:
- # TODO: ref wont be found with another language
- - :to: Handover for Facility Management
+ - :to: :handover_for_facility_management
:type: follows
demo-bcf-management-project:
t_name: (Demo) BCF management
@@ -1470,140 +1476,115 @@ projects:
:bcf_issue_uuid: fbbf9ecf-5721-4bf1-a08c-aed50dc19353
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: f6271a32-acf5-49f8-a1b5-7c445f9158e5
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: f210a2cd-f1f7-4691-b986-2f94117caefe
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: feb97e6e-14fd-4c62-bbad-607f2bb4ebf5
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: 00efc0da-b4d5-4933-bcb6-e01513ee2bcc
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: f9e079a8-02f5-40f0-a08a-171f494ee130
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: f70417a8-174a-42ae-bf1e-a0b6457d0e6f
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: f55d0ec0-9a0f-4222-9926-cc5744888b02
:assigned_to: BIM Modellers
:duration: 4
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: fc560c06-51fc-44fa-81b4-e688be189c6a
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: fe2f9c1f-631b-4b37-91ea-833c4751725a
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: fc5099c0-bedb-4770-a576-0429a7733517
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: 010d9884-8c93-4551-b2bc-570faffe7082
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: febee8e1-1ad2-45e5-b08d-b4be92d25ad6
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: f4d71d45-5a2c-4dad-bcb1-8a4935f2ea69
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: fb9705ea-b32c-46ff-bb6f-d1d049494e05
:assigned_to: BIM Modellers
:duration: 4
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 77
:bcf_issue_uuid: fbe1d941-06ce-45f4-8ccb-ef48b8426f72
:assigned_to: BIM Modellers
:duration: 3
- # TODO: ref wont be found with another language
- :parent: Issue management, first cycle
+ :parent: :issue_management_first_cycle
- :start: 98
:bcf_issue_uuid: 73def76d-939d-404c-9bd0-581399f92714
:duration: 8
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 98
:bcf_issue_uuid: b5105e2e-add1-4d48-abb9-ce51fcea3bdd
:duration: 8
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 98
:bcf_issue_uuid: 99f03fde-4c74-4a8f-940a-c741738ab073
:duration: 2
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 111
:bcf_issue_uuid: af1de642-6d08-489b-8056-ca4c383e0617
:duration: 8
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 114
:bcf_issue_uuid: e6276745-3d58-4d40-80fb-6de5cb05077e
:duration: 8
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 149
:bcf_issue_uuid: efd7be98-1a64-4a35-ad4c-51b8881d79ed
:duration: 8
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 152
:bcf_issue_uuid: f689bfd4-ec09-45ca-bbe3-7d1d0f5d9933
:duration: 21
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 178
:bcf_issue_uuid: 3746180f-ba1e-4ea0-a0fb-6ee69ccabd85
:duration: 8
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
- :start: 178
:bcf_issue_uuid: 2adbdbb4-bb60-4250-b8af-3cd786437814
:duration: 8
- # TODO: ref wont be found with another language
- :parent: Issue management, construction phase
+ :parent: :issue_management_construction_phase
diff --git a/modules/bim/lib/open_project/bim/patches/work_package_seeder_patch.rb b/modules/bim/lib/open_project/bim/patches/work_package_seeder_patch.rb
index 9ae580a8837..873f756a52c 100644
--- a/modules/bim/lib/open_project/bim/patches/work_package_seeder_patch.rb
+++ b/modules/bim/lib/open_project/bim/patches/work_package_seeder_patch.rb
@@ -27,7 +27,7 @@ module OpenProject::Bim::Patches::WorkPackageSeederPatch
def update_parent(work_package, attributes)
return unless attributes['parent']
- parent = WorkPackage.find_by(subject: attributes['parent'])
+ parent = find_work_package(attributes['parent'])
return if parent.nil?
work_package.parent = parent
diff --git a/spec/seeders/demo_data/work_package_seeder_spec.rb b/spec/seeders/demo_data/work_package_seeder_spec.rb
index b8d466319f1..e2a955a89ea 100644
--- a/spec/seeders/demo_data/work_package_seeder_spec.rb
+++ b/spec/seeders/demo_data/work_package_seeder_spec.rb
@@ -209,4 +209,100 @@ describe DemoData::WorkPackageSeeder do
expect(WorkPackage.first.estimated_hours).to be_nil
end
end
+
+ context 'with a parent relation by subject name' do
+ let(:work_packages_data) do
+ [
+ work_package_data(subject: 'Parent'),
+ work_package_data(subject: 'Child', parent: 'Parent')
+ ]
+ end
+
+ it 'creates a parent-child relation between work packages' do
+ expect(WorkPackage.count).to eq(2)
+ expect(WorkPackage.second.parent).to eq(WorkPackage.first)
+ end
+ end
+
+ context 'with a parent relation by reference' do
+ let(:work_packages_data) do
+ [
+ work_package_data(subject: 'Parent', reference: :wp_parent),
+ work_package_data(subject: 'Child', parent: :wp_parent)
+ ]
+ end
+
+ it 'creates a parent-child relation between work packages' do
+ expect(WorkPackage.count).to eq(2)
+ expect(WorkPackage.second.parent).to eq(WorkPackage.first)
+ end
+ end
+
+ context 'with a parent relation by reference inside a nested children property' do
+ let(:work_packages_data) do
+ [
+ work_package_data(subject: 'Grand-parent',
+ children: [
+ work_package_data(subject: 'Parent', reference: :this_one)
+ ]),
+ work_package_data(subject: 'Child', parent: :this_one)
+ ]
+ end
+
+ it 'creates parent-child relations between work packages' do
+ expect(WorkPackage.find_by(subject: 'Child').parent).to eq(WorkPackage.find_by(subject: 'Parent'))
+ expect(WorkPackage.find_by(subject: 'Parent').parent).to eq(WorkPackage.find_by(subject: 'Grand-parent'))
+ end
+ end
+
+ context 'with a parent relation by reference inside a nested children property with a bcf uuid' do
+ let(:bcf_work_package) { create(:work_package, project:) }
+ let(:bcf_issue) { create(:bcf_issue, work_package: bcf_work_package, uuid: 'fbbf9ecf-5721-4bf1-a08c-aed50dc19353') }
+ let(:work_packages_data) do
+ [
+ work_package_data(subject: 'Grand-parent',
+ children: [
+ work_package_data(subject: 'Parent', reference: :this_one)
+ ]),
+ work_package_data(bcf_issue_uuid: bcf_issue.uuid, parent: :this_one)
+ ]
+ end
+
+ it 'creates parent-child relations between work packages' do
+ expect(bcf_work_package.reload.parent).to eq(WorkPackage.find_by(subject: 'Parent'))
+ expect(WorkPackage.find_by(subject: 'Parent').parent).to eq(WorkPackage.find_by(subject: 'Grand-parent'))
+ end
+ end
+
+ context 'with a work package description referencing another work package by a reference name' do
+ let(:work_packages_data) do
+ [
+ work_package_data(subject: 'Major thing to do',
+ reference: :major_thing),
+ work_package_data(subject: 'Other thing',
+ description: 'Please also check [this one]({{opSetting:base_url}}/wp/##wp.id:major_thing).')
+ ]
+ end
+
+ it 'creates parent-child relations between work packages' do
+ wp_major, wp_other = WorkPackage.order(:id).to_a
+ expect(wp_other.description).to eq("Please also check [this one]({{opSetting:base_url}}/wp/#{wp_major.id}).")
+ end
+ end
+
+ context 'with a work package description referencing another work package by subject name' do
+ let(:work_packages_data) do
+ [
+ work_package_data(subject: 'Major thing to do',
+ reference: :major_thing),
+ work_package_data(subject: 'Other thing',
+ description: 'Please also check [this one]({{opSetting:base_url}}/wp/##wp.id:"Major thing to do").')
+ ]
+ end
+
+ it 'creates parent-child relations between work packages' do
+ wp_major, wp_other = WorkPackage.order(:id).to_a
+ expect(wp_other.description).to eq("Please also check [this one]({{opSetting:base_url}}/wp/#{wp_major.id}).")
+ end
+ end
end