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
[#53729] Remove project_custom_field_mapping and the projects aac patch
Dombi Attila81a44b248461
diff --git a/app/contracts/base_contract.rb b/app/contracts/base_contract.rbindex 18838af93b5..f7f78b7a129 100644--- a/app/contracts/base_contract.rb+++ b/app/contracts/base_contract.rb@@ -237,7 +237,7 @@ class BaseContract < Disposable::Twin# as the disabled custom fields would be treated as not-writable## relevant especially for the project API- model.available_custom_fields(global: true).map(&:attribute_name)+ model.all_available_custom_fields.map(&:attribute_name)elsemodel.available_custom_fields.map(&:attribute_name)enddiff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/acts_as_customizable_patches.rbindex f2a33c4e974..0006d173f65 100644--- a/app/models/projects/acts_as_customizable_patches.rb+++ b/app/models/projects/acts_as_customizable_patches.rb@@ -122,7 +122,7 @@ module Projects::ActsAsCustomizablePatchesresultend- def available_custom_fields(global: false)+ def available_custom_fields# overrides acts_as_customizable# in contrast to acts_as_customizable, custom_fields are enabled per project# thus we need to check the project_custom_field_project_mappings@@ -140,6 +140,12 @@ module Projects::ActsAsCustomizablePatches# when accessed with the _query_available_custom_fields_on_global_level flag on.unless _query_available_custom_fields_on_global_levelcustom_fields = custom_fields.visible++ # 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)+ endend# available_custom_fields is called from within the acts_as_customizable module@@ -149,7 +155,7 @@ module Projects::ActsAsCustomizablePatches## additionally we provide the `global` parameter to allow querying the available custom fields on a global level# when we have explicit control over the call of `available_custom_fields`- unless global || new_record? || _query_available_custom_fields_on_global_level+ unless new_record? || _query_available_custom_fields_on_global_levelcustom_fields = custom_fields.where(id: project_custom_field_project_mappings.select(:custom_field_id)).or(ProjectCustomField.required)@@ -158,15 +164,18 @@ module Projects::ActsAsCustomizablePatchescustom_fieldsend- def validate_custom_values- # validate custom values only of a specified section- # instead of validating ALL custom values like done in acts_as_customizable- custom_field_section_ids = CustomField- .where(id: custom_field_values.pluck(:custom_field_id))- .where(custom_field_section_id: _limit_custom_fields_validation_to_section_id)- .pluck(:id)+ def all_available_custom_fields+ with_all_available_custom_fields { available_custom_fields }+ end- super(custom_field_section_ids)+ # Important: In order the have the custom values cache working correctly, all the variables+ # that are factored in the calculation of the available_custom_fields method should be included+ # in the custom_values_cache_key too.+ def custom_values_cache_key+ [+ _query_available_custom_fields_on_global_level || new_record?,+ _limit_custom_fields_validation_to_section_id+ ]end# we need to query the available custom fields on a global level when updating custom field valuesdiff --git a/app/models/work_package.rb b/app/models/work_package.rbindex a1dd265d12a..000adb5b6fc 100644--- a/app/models/work_package.rb+++ b/app/models/work_package.rb@@ -523,7 +523,7 @@ class WorkPackage < ApplicationRecordprivate_class_method :available_custom_field_key- def custom_field_cache_key+ def custom_values_cache_key[project_id, type_id]enddiff --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 16aaf44125a..891562995f8 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@@ -112,7 +112,7 @@ module Redmineenddef custom_field_values- custom_field_values_cache[custom_field_cache_key] ||=+ custom_field_values_cache[custom_values_cache_key] ||=available_custom_fields.flat_map do |custom_field|existing_cvs = custom_values.select { |v| v.custom_field_id == custom_field.id }@@ -132,7 +132,7 @@ module Redmine## i.e.: The work package custom field values are changing based on the project_id and type_id.# The only way to keep the cache updated is to include those ids in the cache key.- def custom_field_cache_key+ def custom_values_cache_key1end@@ -233,12 +233,11 @@ module Redmineself.custom_field_values = new_valuesend- def validate_custom_values(custom_field_ids = [])+ def validate_custom_valuesset_default_values! if new_record?custom_field_values.reject(&:marked_for_destruction?)- .select { |cv| custom_field_ids.empty? || custom_field_ids.include?(cv.custom_field_id) }.select(&:invalid?).each { |custom_value| add_custom_value_errors! custom_value }end