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
[#60183] merge pattern collection on update subject pattern
Eric Schubertd61554501ca1
diff --git a/app/controllers/work_packages/types/subject_configuration_controller.rb b/app/controllers/work_packages/types/subject_configuration_controller.rbindex 973548763e0..82fda439309 100644--- a/app/controllers/work_packages/types/subject_configuration_controller.rb+++ b/app/controllers/work_packages/types/subject_configuration_controller.rb@@ -63,19 +63,29 @@ module WorkPackagesdef tab_path = edit_tab_type_path(id: @type.id, tab: :subject_configuration)def pattern_collection_update(form_params)- case form_params- in { subject_configuration: "generated", pattern: String => blueprint }- { subject: { blueprint:, enabled: true } }- in { subject_configuration: "manual", pattern: String => blueprint }- if blueprint.empty?- # Submitting the form with an empty blueprint and manual subject configuration will- # remove the subject pattern from the collection- nil+ patterns = @type.patterns.to_h++ subject_pattern =+ case form_params+ in { subject_configuration: "generated", pattern: String => blueprint }+ { subject: { blueprint:, enabled: true } }+ in { subject_configuration: "manual", pattern: String => blueprint }+ if blueprint.empty?+ # Submitting the form with an empty blueprint and manual subject configuration will+ # remove the subject pattern from the collection+ nil+ else+ { subject: { blueprint:, enabled: false } }+ endelse- { subject: { blueprint:, enabled: false } }+ nilend++ if subject_pattern.nil?+ patterns.delete("subject")+ patternselse- nil+ patterns.merge(subject_pattern.stringify_keys)endendenddiff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rbindex be20e9813fc..df8228f2e6f 100644--- a/app/helpers/tabs_helper.rb+++ b/app/helpers/tabs_helper.rb@@ -40,7 +40,9 @@ module TabsHelperenddef selected_tab(tabs, default_tab = nil)- tabs.detect { |t| t[:name] == params[:tab] || t[:name] == default_tab } || tabs.first+ tabs.detect { |t| t[:name] == params[:tab] } ||+ tabs.detect { |t| t[:name] == default_tab } ||+ tabs.firstenddef tabs_for_key(key, params = {})diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex 31881f92e72..d145da84d56 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -614,8 +614,6 @@ class PermittedParams:color_id,:default,:description,- :subject_configuration,- :subject_pattern,{ project_ids: [] }],user: %i(diff --git a/app/models/types/patterns/collection.rb b/app/models/types/patterns/collection.rbindex d22c0949b21..cc94bad0907 100644--- a/app/models/types/patterns/collection.rb+++ b/app/models/types/patterns/collection.rb@@ -58,10 +58,6 @@ module Typespatterns.select { |_, pattern| pattern.enabled? }end- def update_pattern(name, blueprint:, enabled:)- self.class.build(patterns: patterns.to_h.merge(name => { blueprint:, enabled: }))- end-def to_hpatterns.stringify_keys.transform_values(&:to_h)enddiff --git a/spec/controllers/work_packages/types/subject_configuration_controller_spec.rb b/spec/controllers/work_packages/types/subject_configuration_controller_spec.rbindex abda6f41b38..d6356048534 100644--- a/spec/controllers/work_packages/types/subject_configuration_controller_spec.rb+++ b/spec/controllers/work_packages/types/subject_configuration_controller_spec.rb@@ -40,7 +40,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationController docontext "when the user is not logged in" dolet(:user) { User.anonymous }- it "responds with forbidden" do+ it "requires login" doput :update_subject_configuration, params: { id: wp_type.id }expect(response.status).to redirect_to signin_url(back_url: subject_configuration_type_url(wp_type))end@@ -73,7 +73,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationController docontext "if form data is invalid" dolet(:form_data) { { subject_configuration: "generated", pattern: nil } }- let(:expected_pattern_data) { { subject: { blueprint: "", enabled: true } } }+ let(:expected_pattern_data) { { "subject" => { blueprint: "", enabled: true } } }let(:service_result) { ServiceResult.failure }it "renders the edit template" do@@ -85,7 +85,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationController docontext "if form data is valid" docontext "with generated subject configuration" dolet(:form_data) { { subject_configuration: "generated", pattern: "Vacation - {{assignee}}" } }- let(:expected_pattern_data) { { subject: { blueprint: "Vacation - {{assignee}}", enabled: true } } }+ let(:expected_pattern_data) { { "subject" => { blueprint: "Vacation - {{assignee}}", enabled: true } } }let(:service_result) { ServiceResult.success }it "redirects to the current tab path" do@@ -95,7 +95,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationController docontext "with manual subject configuration, but still persisted blueprint" dolet(:form_data) { { subject_configuration: "manual", pattern: "Vacation - {{assignee}}" } }- let(:expected_pattern_data) { { subject: { blueprint: "Vacation - {{assignee}}", enabled: false } } }+ let(:expected_pattern_data) { { "subject" => { blueprint: "Vacation - {{assignee}}", enabled: false } } }let(:service_result) { ServiceResult.success }it "redirects to the current tab path" do@@ -105,7 +105,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationController docontext "with manual subject configuration and no blueprint" dolet(:form_data) { { subject_configuration: "manual", pattern: nil } }- let(:expected_pattern_data) { nil }+ let(:expected_pattern_data) { {} }let(:service_result) { ServiceResult.success }it "redirects to the current tab path" do