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

Introduce custom_field_values_to_validate method to control section based validation

Dombi Attila0b3059928285
diff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/acts_as_customizable_patches.rb
index 772d07a2f7a..dd63a7c89e8 100644
--- a/app/models/projects/acts_as_customizable_patches.rb
+++ b/app/models/projects/acts_as_customizable_patches.rb
@@ -163,14 +163,15 @@ module Projects::ActsAsCustomizablePatches
with_all_available_custom_fields { available_custom_fields }
end
- def custom_fields_to_validate
- custom_fields = available_custom_fields
+ def custom_field_values_to_validate
# Limit the set of available custom fields when the validation is limited to a section
if _limit_custom_fields_validation_to_section_id
- custom_fields =
- custom_fields.where(custom_field_section_id: _limit_custom_fields_validation_to_section_id)
+ custom_field_values.select do |cfv|
+ cfv.custom_field.custom_field_section_id == _limit_custom_fields_validation_to_section_id
+ end
+ else
+ custom_field_values
end
- custom_fields
end
# we need to query the available custom fields on a global level when updating custom field values
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.rb
index 197fd31b8ad..e95c846b5b2 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
@@ -233,14 +233,13 @@ module Redmine
self.custom_field_values = new_values
end
- def custom_fields_to_validate
+ def custom_field_values_to_validate
custom_field_values
end
def validate_custom_values
set_default_values! if new_record?
-
- custom_fields_to_validate
+ custom_field_values_to_validate
.reject(&:marked_for_destruction?)
.select(&:invalid?)
.each { |custom_value| add_custom_value_errors! custom_value }