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
[#60666] User can't save lifecycle modal if project is invalid
Dombi Attila14725bce4040
diff --git a/app/contracts/projects/base_contract.rb b/app/contracts/projects/base_contract.rbindex 8b8fa191161..a87171dd273 100644--- a/app/contracts/projects/base_contract.rb+++ b/app/contracts/projects/base_contract.rb@@ -57,6 +57,10 @@ module Projectsvalidate :validate_user_allowed_to_manage+ def valid?(context = :saving_custom_fields)+ super+ end+def assignable_parentsProject.allowed_to(user, :add_subprojects)diff --git a/app/models/project.rb b/app/models/project.rbindex 5bdb1f1f83f..8bbc1e8e713 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -100,7 +100,8 @@ class Project < ApplicationRecordacts_as_favorable- acts_as_customizable # extended in Projects::CustomFields in order to support sections+ acts_as_customizable validate_on: :saving_custom_fields+ # extended in Projects::CustomFields in order to support sections# and project-level activation of custom fieldsacts_as_searchable columns: %W(#{table_name}.name #{table_name}.identifier #{table_name}.description),diff --git a/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb b/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rbindex 68a790884cb..20393e25323 100644--- a/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb+++ b/lib_static/plugins/acts_as_customizable/lib/acts_as_customizable.rb@@ -49,7 +49,9 @@ module Redminedependent: :delete_all,validate: false,autosave: true- validate :validate_custom_values++ validation_options = options[:validate_on] ? { on: options[:validate_on] } : {}+ validate :validate_custom_values, **validation_optionssend :include, Redmine::Acts::Customizable::InstanceMethodsbefore_save :ensure_custom_values_completediff --git a/spec/models/projects/customizable_spec.rb b/spec/models/projects/customizable_spec.rbindex 0fc00837e6b..c6886e0622e 100644--- a/spec/models/projects/customizable_spec.rb+++ b/spec/models/projects/customizable_spec.rb@@ -224,9 +224,9 @@ RSpec.describe Project, "customizable" dobool_custom_field.id => true})- expect(project).not_to be_valid+ expect(project).not_to be_valid(:saving_custom_fields)- expect { project.save! }.to raise_error(ActiveRecord::RecordInvalid)+ expect { project.save!(context: :saving_custom_fields) }.to raise_error(ActiveRecord::RecordInvalid)endit "validates only custom values of a section if section scope is provided while updating" do@@ -236,7 +236,7 @@ RSpec.describe Project, "customizable" dorequired_text_custom_field.id => "bar"})- expect(project).to be_valid+ expect(project).to be_valid(:saving_custom_fields)# after a project is created, a new required custom field is added# which gets automatically activated for all projects@@ -245,20 +245,20 @@ RSpec.describe Project, "customizable" doproject_custom_field_section: another_section)# thus, the project is invalid in total- expect(project.reload).not_to be_valid- expect { project.save! }.to raise_error(ActiveRecord::RecordInvalid)+ expect(project.reload).not_to be_valid(:saving_custom_fields)+ expect { project.save!(context: :saving_custom_fields) }.to raise_error(ActiveRecord::RecordInvalid)# but we still want to allow updating other sections without invalid required custom field values# by limiting the validation scope to a section temporarilyproject._limit_custom_fields_validation_to_section_id = section.id- expect(project).to be_valid+ expect(project).to be_valid(:saving_custom_fields)- expect { project.save! }.not_to raise_error+ expect { project.save!(context: :saving_custom_fields) }.not_to raise_error# Removing the section scoped limitation should result a validation error again.project._limit_custom_fields_validation_to_section_id = nil- expect { project.save! }.to raise_error(ActiveRecord::RecordInvalid)+ expect { project.save!(context: :saving_custom_fields) }.to raise_error(ActiveRecord::RecordInvalid)endendend