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
add validation to relations to check if to and from are selected
Behrokh Satarnejad3e96e4e46032
diff --git a/app/contracts/relations/base_contract.rb b/app/contracts/relations/base_contract.rbindex 82c4d5edc2e..1caaaa0ca6f 100644--- a/app/contracts/relations/base_contract.rb+++ b/app/contracts/relations/base_contract.rb@@ -55,7 +55,7 @@ module Relationsenddef validate_nodes_relatable- if (model.from_id_changed? || model.to_id_changed?) &&+ if (model.from_id_changed? || model.to_id_changed?) && (model.from_id.present? && model.to_id.present?) &&WorkPackage.relatable(model.from, model.relation_type, ignored_relation: model).where(id: model.to_id).empty?errors.add :base, I18n.t(:"activerecord.errors.messages.circular_dependency")enddiff --git a/app/models/relation.rb b/app/models/relation.rbindex aede485a7d8..0e195286d7c 100644--- a/app/models/relation.rb+++ b/app/models/relation.rb@@ -105,7 +105,9 @@ class Relation < ApplicationRecordvalidates :lag, numericality: { allow_nil: true }- validates :to, uniqueness: { scope: :from }+ validates :to, presence: true, uniqueness: { scope: :from }++ validates :from, presence: truebefore_validation :reverse_if_neededdiff --git a/spec/contracts/relations/shared_contract_examples.rb b/spec/contracts/relations/shared_contract_examples.rbindex 8511d4a368b..a880c3eb949 100644--- a/spec/contracts/relations/shared_contract_examples.rb+++ b/spec/contracts/relations/shared_contract_examples.rb@@ -115,6 +115,18 @@ RSpec.shared_examples_for "relation contract" doit_behaves_like "contract is invalid", from: :error_not_foundend+ context "when no from value is set" do+ let(:relation_from) { nil }++ it_behaves_like "contract is invalid", from: :error_not_found+ end++ context "when no to value is set" do+ let(:relation_to) { nil }++ it_behaves_like "contract is invalid", to: :error_not_found+ end+context "when the work package for to is not visible" dolet(:relation_to_visible) { false }