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
Very basically allow to update subject patterns
Jan Sandbrinka61ab846d2d2
diff --git a/app/components/work_packages/types/subject_configuration_component.rb b/app/components/work_packages/types/subject_configuration_component.rbindex c5b6fb0905c..02aea69386d 100644--- a/app/components/work_packages/types/subject_configuration_component.rb+++ b/app/components/work_packages/types/subject_configuration_component.rb@@ -36,8 +36,8 @@ module WorkPackagesdef form_options{- url: "https://example.com",- method: :put,+ url: update_type_tab_path(id: model.id, tab: "subject_configuration"),+ method: :patch,model:,data: {application_target: "dynamic",diff --git a/app/contracts/types/base_contract.rb b/app/contracts/types/base_contract.rbindex 5f8c5b02db9..4f189e300fd 100644--- a/app/contracts/types/base_contract.rb+++ b/app/contracts/types/base_contract.rb@@ -42,6 +42,7 @@ module Typesattribute :project_idsattribute :descriptionattribute :attribute_groups+ attribute :patternsvalidate :validate_current_user_is_adminvalidate :validate_attribute_group_namesdiff --git a/app/forms/work_packages/types/subject_configuration_form.rb b/app/forms/work_packages/types/subject_configuration_form.rbindex 0c30af24e74..2c1076e2ed7 100644--- a/app/forms/work_packages/types/subject_configuration_form.rb+++ b/app/forms/work_packages/types/subject_configuration_form.rb@@ -58,7 +58,8 @@ module WorkPackagessubject_form.group(data: { "admin--subject-configuration-target": "patternInput" }) do |toggleable_group|toggleable_group.text_field(- name: :pattern,+ name: :subject_pattern,+ value: subject_pattern,label: I18n.t("types.edit.subject_configuration.pattern.label"),caption: I18n.t("types.edit.subject_configuration.pattern.caption"),required: true,@@ -74,6 +75,12 @@ module WorkPackagesdef has_pattern?self.class.has_pattern?(model)end++ def subject_pattern+ return "" if model.patterns.nil? || model.patterns[:subject].nil?++ model.patterns[:subject].blueprint+ endendendenddiff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rbindex d145da84d56..31881f92e72 100644--- a/app/models/permitted_params.rb+++ b/app/models/permitted_params.rb@@ -614,6 +614,8 @@ 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 e1dda360e4c..2b29e620520 100644--- a/app/models/types/patterns/collection.rb+++ b/app/models/types/patterns/collection.rb@@ -51,7 +51,7 @@ module Typesenddef [](value)- patterns.fetch(value)+ patterns[value]enddef to_hdiff --git a/app/services/base_type_service.rb b/app/services/base_type_service.rbindex 36750ca1a46..1e41f1cc126 100644--- a/app/services/base_type_service.rb+++ b/app/services/base_type_service.rb@@ -71,7 +71,9 @@ class BaseTypeServicedef set_params_and_validate(params)# Only set attribute groups when it exists# (Regression #28400)- set_attribute_groups(params) unless params[:attribute_groups].nil?+ set_attribute_groups(params) if params[:attribute_groups]++ set_subject_pattern(params) if params[:subject_configuration]# This should go before `set_scalar_params` call to get the# project_ids, custom_field_ids diffs from the type and the params.@@ -92,7 +94,7 @@ class BaseTypeServiceenddef set_scalar_params(params)- type.attributes = params.except(:attribute_groups)+ type.attributes = params.except(:attribute_groups, :subject_configuration, :subject_pattern)enddef set_attribute_groups(params)@@ -103,6 +105,15 @@ class BaseTypeServiceendend+ def set_subject_pattern(params)+ type.patterns = {+ subject: {+ blueprint: params[:subject_pattern],+ enabled: params[:subject_configuration] == "auto"+ }+ }+ end+def parse_attribute_groups_params(params)return if params[:attribute_groups].nil?diff --git a/spec/controllers/types_controller_spec.rb b/spec/controllers/types_controller_spec.rbindex bd789fd263e..63ddce35c48 100644--- a/spec/controllers/types_controller_spec.rb+++ b/spec/controllers/types_controller_spec.rb@@ -312,6 +312,57 @@ RSpec.describe TypesController doexpect(Type.find_by(name: "My type").projects.count).to eq(0)endend++ describe "when updating the subject pattern" do+ let(:params) do+ { "id" => type.id,+ "type" => { subject_pattern: blueprint, subject_configuration: "auto" },+ "tab" => "subject_configuration" }+ end+ let(:blueprint) { "I choose you {{assignee}}!" }++ before do+ patch :update, params:+ end++ it { expect(response).to be_redirect }++ it do+ expect(response).to(+ redirect_to(edit_type_tab_path(id: type.id, tab: "subject_configuration"))+ )+ end++ it "stores the pattern" do+ pattern = Type.find(type.id).patterns[:subject]++ expect(pattern).to be_present+ expect(pattern).to be_enabled+ expect(pattern.blueprint).to eq(blueprint)+ end++ context "and when the subject is configured manually" do+ let(:params) do+ { "id" => type.id,+ "type" => { subject_pattern: blueprint, subject_configuration: "manual" },+ "tab" => "subject_configuration" }+ end++ it "disables the pattern" do+ pattern = Type.find(type.id).patterns[:subject]++ expect(pattern).to be_present+ expect(pattern).not_to be_enabled+ end++ it "stores the previously used blueprint" do+ pattern = Type.find(type.id).patterns[:subject]++ expect(pattern).to be_present+ expect(pattern.blueprint).to eq(blueprint)+ end+ end+ endenddescribe "POST move" do