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
Correct permitted params depending on the relation direction and add a test case
Henriette Dargeb3a7fc55cd24
diff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rbindex 2af79aac70c..e949dec1758 100644--- a/app/controllers/work_package_relations_controller.rb+++ b/app/controllers/work_package_relations_controller.rb@@ -69,15 +69,6 @@ class WorkPackageRelationsController < ApplicationControllerendrespond_with_relations_tab_update(service_result, relation_to_scroll_to: service_result.result)-- if service_result.failure?- update_via_turbo_stream(- component: WorkPackageRelationsTab::WorkPackageRelationFormComponent.new(work_package: @work_package,- relation: service_result.result,- base_errors: service_result.errors[:base]),- status: :bad_request- )- endenddef update@@ -87,6 +78,7 @@ class WorkPackageRelationsController < ApplicationController.call(update_relation_params)respond_with_relations_tab_update(service_result)+if service_result.failure?update_via_turbo_stream(component: WorkPackageRelationsTab::WorkPackageRelationFormComponent.new(work_package: @work_package,@@ -127,9 +119,15 @@ class WorkPackageRelationsController < ApplicationControllerenddef create_relation_params- params.require(:relation)- .permit(:relation_type, :to_id, :description, :lag)- .merge(from_id: @work_package.id)+ if params[:relation][:from_id].present?+ params.require(:relation)+ .permit(:relation_type, :from_id, :description, :lag)+ .merge(to_id: @work_package.id)+ else+ params.require(:relation)+ .permit(:relation_type, :to_id, :description, :lag)+ .merge(from_id: @work_package.id)+ endenddef update_relation_paramsdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 2bd3404b2f3..f30e20e7e3c 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -976,7 +976,7 @@ en:timeline_labels: "Timeline labels"relation:lag: "Lag"- from: "Work package"+ from: "Related work package"to: "Related work package"reminder:remind_at_date: "Date"@@ -1302,10 +1302,10 @@ en:circular_dependency: "The relationship creates a circle of relationships."attributes:to_id:- error_not_found: "work package not found or not visible"+ error_not_found: "not found or not visible"error_readonly: "an existing relation's `to` link is immutable"from_id:- error_not_found: "work package not found or not visible"+ error_not_found: "not found or not visible"error_readonly: "an existing relation's `from` link is immutable"lag:greater_than_or_equal_to:diff --git a/spec/features/work_packages/details/relations/primerized_relations_spec.rb b/spec/features/work_packages/details/relations/primerized_relations_spec.rbindex fbfa7e850e2..38670b78f1f 100644--- a/spec/features/work_packages/details/relations/primerized_relations_spec.rb+++ b/spec/features/work_packages/details/relations/primerized_relations_spec.rb@@ -300,13 +300,15 @@ RSpec.describe "Primerized work package relations tab",describe "creating a relation" dolet(:wp_successor) { create(:work_package, type: type1, subject: "successor of main") }+ let(:wp_blocks) { create(:work_package, type: type1, subject: "I am blocking") }it "renders the new relation form for the selected type and creates the relation" doscroll_to_element relations_panelwait_for_network_idle- relations_tab.add_relation(type: :precedes, relatable: wp_successor,+ relations_tab.add_relation(type: :precedes,+ relatable: wp_successor,description: "Discovered relations have descriptions!")relations_tab.expect_relation(wp_successor)@@ -320,6 +322,33 @@ RSpec.describe "Primerized work package relations tab",relations_tab.expect_ghost_relation(restricted_child_work_package)end+ it "renders an error when there is no WP selected (regression #60869)" do+ scroll_to_element relations_panel++ wait_for_network_idle++ relations_tab.select_relation_type("Blocked by")++ wait_for_network_idle++ click_link_or_button "Add"++ wait_for_network_idle++ expect(page).to have_text "Related work package not found or not visible"++ relations_tab.search_in_autocompleter(wp_blocks)++ click_link_or_button "Add"++ relations_tab.expect_relation(wp_blocks)++ # Bumped by one+ tabs.expect_counter("relations", 7)+ # Relation is created+ expect(Relation.blocks.where(from: wp_blocks, to: work_package)).to exist+ end+it "does not autocomplete unrelatable work packages" do# wp_predecessor is already related to work_package as relation_follows# in a predecessor relation, so it should not be autocompleteable anymorediff --git a/spec/models/queries/relations/filters/from_filter_spec.rb b/spec/models/queries/relations/filters/from_filter_spec.rbindex 36e21068735..4f513aae43b 100644--- a/spec/models/queries/relations/filters/from_filter_spec.rb+++ b/spec/models/queries/relations/filters/from_filter_spec.rb@@ -38,7 +38,7 @@ RSpec.describe Queries::Relations::Filters::FromFilter dolet(:class_key) { :from_id }let(:type) { :integer }# The name is not very good but as long as the filter is not displayed in the UI ...- let(:human_name) { "Work package" }+ let(:human_name) { "Related work package" }describe "#allowed_values" doit "is nil" dodiff --git a/spec/requests/api/v3/relations/relations_api_spec.rb b/spec/requests/api/v3/relations/relations_api_spec.rbindex 289bce0d032..bfb09356e47 100644--- a/spec/requests/api/v3/relations/relations_api_spec.rb+++ b/spec/requests/api/v3/relations/relations_api_spec.rb@@ -303,7 +303,7 @@ RSpec.describe "API v3 Relation resource", content_type: :json doit "lets the user know the attribute is read-only" domsg = JSON.parse(last_response.body)["message"]- expect(msg).to include "Work package an existing relation's `from` link is immutable"+ expect(msg).to include "Related work package an existing relation's `from` link is immutable"endendenddiff --git a/spec/support/components/work_packages/relations.rb b/spec/support/components/work_packages/relations.rbindex 75b04de4c40..31f38e7f356 100644--- a/spec/support/components/work_packages/relations.rb+++ b/spec/support/components/work_packages/relations.rb@@ -183,10 +183,7 @@ module Componentsexpect(page).to have_text(modal_heading_label)# Enter the query and select the child- autocomplete_field = page.find_test_selector("work-package-relation-form-to-id")- select_autocomplete(autocomplete_field,- query: relatable.subject,- results_selector: "body")+ search_in_autocompleter(relatable)if description.present?fill_in "Description", with: description@@ -206,6 +203,13 @@ module Componentsfind_row(target_wp)end+ def search_in_autocompleter(relatable)+ autocomplete_field = page.find_test_selector("work-package-relation-form-to-id")+ select_autocomplete(autocomplete_field,+ query: relatable.subject,+ results_selector: "body")+ end+def edit_relation_description(relatable, description)open_relation_dialog(relatable)