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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
remove confusing relations associations
ulferts2583e03c077e
diff --git a/app/models/work_packages/relations.rb b/app/models/work_packages/relations.rbindex f3df1fd05b4..e61e8d55fda 100644--- a/app/models/work_packages/relations.rb+++ b/app/models/work_packages/relations.rb@@ -28,28 +28,6 @@ module WorkPackages::Relationsextend ActiveSupport::Concernincluded do- # Relations pointing to another work package.- # In this case,- # * from is self- # * to is the other work package involved- has_many :relations_to,- class_name: 'Relation',- foreign_key: :from_id,- autosave: true,- dependent: :nullify,- inverse_of: :from-- # Relations pointing away from the work package.- # In this case,- # * to is self- # * from is the other work package involved- has_many :relations_from,- class_name: 'Relation',- foreign_key: :to_id,- autosave: true,- dependent: :nullify,- inverse_of: :to-# Relations where the current work package follows another one.# In this case,# * from is self.iddiff --git a/app/services/projects/copy/work_packages_dependent_service.rb b/app/services/projects/copy/work_packages_dependent_service.rbindex d7953c8d206..d28db629db2 100644--- a/app/services/projects/copy/work_packages_dependent_service.rb+++ b/app/services/projects/copy/work_packages_dependent_service.rb@@ -94,27 +94,14 @@ module Projects::Copyendend- def copy_relations(wp, new_wp_id, work_packages_map)- wp.relations_to.each do |source_relation|- new_relation = Relation.new- new_relation.attributes = source_relation.attributes.dup.except('id', 'from_id', 'to_id')- new_relation.to_id = work_packages_map[source_relation.to_id]- if new_relation.to_id.nil? && Setting.cross_project_work_package_relations?- new_relation.to_id = source_relation.to_id- end- new_relation.from_id = new_wp_id- new_relation.save- end-- wp.relations_from.each do |source_relation|- new_relation = Relation.new- new_relation.attributes = source_relation.attributes.dup.except('id', 'from_id', 'to_id')- new_relation.from_id = work_packages_map[source_relation.from_id]- if new_relation.from_id.nil? && Setting.cross_project_work_package_relations?- new_relation.from_id = source_relation.from_id- end- new_relation.to_id = new_wp_id- new_relation.save+ def copy_relations(source_wp, new_wp_id, work_packages_map)+ Relation.of_work_package(source_wp).each do |source_relation|+ from_id, to_id = relations_from_to(source_relation, source_wp, new_wp_id, work_packages_map)++ Relation.create(source_relation+ .attributes+ .except('id', 'from_id', 'to_id')+ .merge(to_id: to_id, from_id: from_id))endend@@ -165,5 +152,17 @@ module Projects::Copy@principals ||= Principal.possible_assignee(project).pluck(:id).to_setprincipal_id if @principals.include?(principal_id)end++ def relations_from_to(source_relation, source_wp, new_wp_id, work_packages_map)+ if source_relation.from_id == source_wp.id+ [new_wp_id,+ work_packages_map[source_relation.to_id] ||+ (Setting.cross_project_work_package_relations? && source_relation.to_id)]+ else+ [work_packages_map[source_relation.from_id] ||+ (Setting.cross_project_work_package_relations? && source_relation.from_id),+ new_wp_id]+ end+ endendenddiff --git a/modules/backlogs/spec/services/impediments/create_services_spec.rb b/modules/backlogs/spec/services/impediments/create_services_spec.rbindex 76e6e48a33b..f92cf8d25bc 100644--- a/modules/backlogs/spec/services/impediments/create_services_spec.rb+++ b/modules/backlogs/spec/services/impediments/create_services_spec.rb@@ -83,14 +83,15 @@ describe Impediments::CreateService doshared_examples_for 'impediment creation with 1 blocking relationship' doit_should_behave_like 'impediment creation'- it { expect(subject.relations_to.size).to eq(1) }- it { expect(subject.relations_to[0].to).to eql feature }- it { expect(subject.relations_to[0].relation_type).to eql Relation::TYPE_BLOCKS }++ it { expect(subject.blocks_relations.size).to eq(1) }+ it { expect(subject.blocks_relations[0].to).to eql feature }endshared_examples_for 'impediment creation with no blocking relationship' doit_should_behave_like 'impediment creation'- it { expect(subject.relations_to.size).to eq(0) }++ it { expect(subject.blocks_relations.size).to eq(0) }enddescribe 'WITH a blocking relationship to a story' do@@ -113,7 +114,7 @@ describe Impediments::CreateService doit_should_behave_like 'impediment creation with 1 blocking relationship'it { expect(subject).not_to be_new_record }- it { expect(subject.relations_to[0]).not_to be_new_record }+ it { expect(subject.blocks_relations[0]).not_to be_new_record }enddescribe 'WITH the story having another version' do