Skip to content

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

[#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.rb
index 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 WorkPackages
def 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 } }
+ end
else
- { subject: { blueprint:, enabled: false } }
+ nil
end
+
+ if subject_pattern.nil?
+ patterns.delete("subject")
+ patterns
else
- nil
+ patterns.merge(subject_pattern.stringify_keys)
end
end
end
diff --git a/app/helpers/tabs_helper.rb b/app/helpers/tabs_helper.rb
index be20e9813fc..df8228f2e6f 100644
--- a/app/helpers/tabs_helper.rb
+++ b/app/helpers/tabs_helper.rb
@@ -40,7 +40,9 @@ module TabsHelper
end
def 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.first
end
def tabs_for_key(key, params = {})
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index 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.rb
index d22c0949b21..cc94bad0907 100644
--- a/app/models/types/patterns/collection.rb
+++ b/app/models/types/patterns/collection.rb
@@ -58,10 +58,6 @@ module Types
patterns.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_h
patterns.stringify_keys.transform_values(&:to_h)
end
diff --git a/spec/controllers/work_packages/types/subject_configuration_controller_spec.rb b/spec/controllers/work_packages/types/subject_configuration_controller_spec.rb
index 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 do
context "when the user is not logged in" do
let(:user) { User.anonymous }
- it "responds with forbidden" do
+ it "requires login" do
put :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 do
context "if form data is invalid" do
let(: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 do
context "if form data is valid" do
context "with generated subject configuration" do
let(: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 do
context "with manual subject configuration, but still persisted blueprint" do
let(: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 do
context "with manual subject configuration and no blueprint" do
let(: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