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
Show error messages for both `from_id` and `to_id` fields in the relations dialog
Henriette Darge7a243a54cf31
diff --git a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erbindex a9bb8a96c45..bfd9090c7e0 100644--- a/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb+++ b/app/components/work_package_relations_tab/work_package_relation_form_component.html.erb@@ -20,15 +20,16 @@# so we need to re-define them here. Figure out solution for this.relation = @relationlag_shown = show_lag?- to_id_field_value = relation.to.present? ? "#{related_work_package.type.name.upcase} ##{related_work_package.id} - #{related_work_package.subject}" : nil+ field_value = displayable_field_value+ relation_direction = directionurl = ::API::V3::Utilities::PathHelper::ApiV3Path.work_package_available_relation_candidates(@work_package.id, type: relation.relation_type_for(@work_package))render_inline_form(f) do |my_form|if relation.persisted?my_form.text_field(- name: :to_id,+ name: relation_direction,label: WorkPackage.model_name.human,visually_hide_label: false,- value: to_id_field_value,+ value: field_value,readonly: true)else@@ -38,7 +39,7 @@)my_form.autocompleter(- name: :to_id,+ name: relation_direction,label: WorkPackage.model_name.human,required: true,visually_hide_label: false,diff --git a/app/components/work_package_relations_tab/work_package_relation_form_component.rb b/app/components/work_package_relations_tab/work_package_relation_form_component.rbindex 264d08770fa..14ad7e21fcc 100644--- a/app/components/work_package_relations_tab/work_package_relation_form_component.rb+++ b/app/components/work_package_relations_tab/work_package_relation_form_component.rb@@ -51,10 +51,22 @@ class WorkPackageRelationsTab::WorkPackageRelationFormComponent < ApplicationComrelated = @relation.to# We cannot rely on the related WorkPackage being the "to",# depending on the relation it can also be "from"- related.id == @work_package.id ? @relation.from : related+ related.present? && related.id == @work_package.id ? @relation.from : relatedendend+ def displayable_field_value+ return nil if related_work_package.nil?++ if @relation.to.present?+ "#{related_work_package.type.name.upcase} ##{related_work_package.id} - #{related_work_package.subject}"+ end+ end++ def direction+ @relation.to.present? ? :from_id : :to_id+ end+def submit_url_optionsif @relation.persisted?{ method: :patch,@@ -66,6 +78,6 @@ class WorkPackageRelationsTab::WorkPackageRelationFormComponent < ApplicationComenddef show_lag?- @relation.relation_type == Relation::TYPE_PRECEDES || @relation.relation_type == Relation::TYPE_FOLLOWS+ [Relation::TYPE_PRECEDES, Relation::TYPE_FOLLOWS].include?(@relation.relation_type)endenddiff --git a/app/contracts/relations/base_contract.rb b/app/contracts/relations/base_contract.rbindex 9970593a8eb..c334dc2263a 100644--- a/app/contracts/relations/base_contract.rb+++ b/app/contracts/relations/base_contract.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -47,11 +49,11 @@ module Relationsprivatedef validate_from_exists- errors.add :from, :error_not_found unless visible_work_packages.exists? model.from_id+ errors.add :from_id, :error_not_found unless visible_work_packages.exists? model.from_idenddef validate_to_exists- errors.add :to, :error_not_found unless visible_work_packages.exists? model.to_id+ errors.add :to_id, :error_not_found unless visible_work_packages.exists? model.to_idenddef validate_nodes_relatable@@ -60,7 +62,7 @@ module Relations# in this case we only want to show the "WorkPackage can't be blank" error instead of a# misleading circular dependencies error# the error is added by the models presence validation- return if model.to_id.nil?+ return if model.to_id.nil? || model.from_id.nil?if (model.from_id_changed? || model.to_id_changed?) &&WorkPackage.relatable(model.from, model.relation_type, ignored_relation: model).where(id: model.to_id).empty?@@ -85,6 +87,8 @@ module Relationsenddef manage_relations?+ return true if model.from.nil?+user.allowed_in_work_package?(:manage_work_package_relations, model.from)endenddiff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rbindex dbdef5d38a3..2af79aac70c 100644--- a/app/controllers/work_package_relations_controller.rb+++ b/app/controllers/work_package_relations_controller.rb@@ -59,7 +59,7 @@ class WorkPackageRelationsController < ApplicationControllerservice_result = Relations::CreateService.new(user: current_user).call(create_relation_params)- unless service_result.success?+ if service_result.failure?update_via_turbo_stream(component: WorkPackageRelationsTab::WorkPackageRelationFormComponent.new(work_package: @work_package,relation: service_result.result,diff --git a/app/models/relation.rb b/app/models/relation.rbindex 5b9875e920c..1cad5d0bc23 100644--- a/app/models/relation.rb+++ b/app/models/relation.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -30,22 +32,22 @@ class Relation < ApplicationRecordbelongs_to :from, class_name: "WorkPackage"belongs_to :to, class_name: "WorkPackage"- TYPE_RELATES = "relates".freeze- TYPE_PRECEDES = "precedes".freeze- TYPE_FOLLOWS = "follows".freeze- TYPE_BLOCKS = "blocks".freeze- TYPE_BLOCKED = "blocked".freeze- TYPE_DUPLICATES = "duplicates".freeze- TYPE_DUPLICATED = "duplicated".freeze- TYPE_INCLUDES = "includes".freeze- TYPE_PARTOF = "partof".freeze- TYPE_REQUIRES = "requires".freeze- TYPE_REQUIRED = "required".freeze+ TYPE_RELATES = "relates"+ TYPE_PRECEDES = "precedes"+ TYPE_FOLLOWS = "follows"+ TYPE_BLOCKS = "blocks"+ TYPE_BLOCKED = "blocked"+ TYPE_DUPLICATES = "duplicates"+ TYPE_DUPLICATED = "duplicated"+ TYPE_INCLUDES = "includes"+ TYPE_PARTOF = "partof"+ TYPE_REQUIRES = "requires"+ TYPE_REQUIRED = "required"# The parent/child relation is maintained separately# (in WorkPackage and WorkPackageHierarchy) and a relation cannot# have the type 'parent' but this is abstracted to simplify the code.- TYPE_PARENT = "parent".freeze- TYPE_CHILD = "child".freeze+ TYPE_PARENT = "parent"+ TYPE_CHILD = "child"TYPES = {TYPE_RELATES => {@@ -109,8 +111,7 @@ class Relation < ApplicationRecordgreater_than_or_equal_to: 0}- # The primer form depends on to_id being validated- validates :to_id, uniqueness: { scope: :from }, presence: true+ validates :to, uniqueness: { scope: :from }before_validation :reverse_if_neededdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex e075a6954ea..2bd3404b2f3 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1301,11 +1301,11 @@ en:typed_dag:circular_dependency: "The relationship creates a circle of relationships."attributes:- to:- error_not_found: "work package in `to` position not found or not visible"+ to_id:+ error_not_found: "work package not found or not visible"error_readonly: "an existing relation's `to` link is immutable"- from:- error_not_found: "work package in `from` position not found or not visible"+ from_id:+ error_not_found: "work package not found or not visible"error_readonly: "an existing relation's `from` link is immutable"lag:greater_than_or_equal_to: