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

Remove the for_custom_field_accessor patch only

Dombi Attilab589dcce0de8
diff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/acts_as_customizable_patches.rb
index 92467c2e30b..00d7ad8b436 100644
--- a/app/models/projects/acts_as_customizable_patches.rb
+++ b/app/models/projects/acts_as_customizable_patches.rb
@@ -54,9 +54,7 @@ module Projects::ActsAsCustomizablePatches
# 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
- custom_fields = ProjectCustomField
- .includes(:project_custom_field_section)
- .order("custom_field_sections.position", :position_in_custom_field_section)
+ custom_fields = all_available_custom_fields
# Do not hide the invisble fields when accessing via the _query_available_custom_fields_on_global_level
# flag. Due to the internal working of the acts_as_customizable plugin, when a project admin updates
@@ -87,7 +85,9 @@ module Projects::ActsAsCustomizablePatches
end
def all_available_custom_fields
- with_all_available_custom_fields { available_custom_fields }
+ ProjectCustomField
+ .includes(:project_custom_field_section)
+ .order("custom_field_sections.position", :position_in_custom_field_section)
end
def custom_field_values_to_validate
@@ -106,14 +106,5 @@ module Projects::ActsAsCustomizablePatches
def custom_field_values=(values)
with_all_available_custom_fields { super }
end
-
- # We need to query the available custom fields on a global level when
- # trying to set a custom field which is not enabled via the API e.g. custom_field_123="foo"
- # This implies implicit activation of the disabled custom fields via the API. As a side effect,
- # we will have empty CustomValue objects created for each custom field, regardless of its
- # enabled/disabled state in the project.
- def for_custom_field_accessor(method_symbol)
- with_all_available_custom_fields { super }
- end
end
end
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 e95c846b5b2..9c432079993 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
@@ -72,6 +72,10 @@ module Redmine
self.class.available_custom_fields(self)
end
+ def all_available_custom_fields
+ available_custom_fields
+ end
+
# Sets the values of the object's custom fields
# values is an array like [{'id' => 1, 'value' => 'foo'}, {'id' => 2, 'value' => 'bar'}]
def custom_fields=(values)
@@ -333,7 +337,7 @@ module Redmine
def for_custom_field_accessor(method_symbol)
match = /\Acustom_field_(?<id>\d+)=?\z/.match(method_symbol.to_s)
if match
- custom_field = available_custom_fields.find { |cf| cf.id.to_s == match[:id] }
+ custom_field = all_available_custom_fields.find { |cf| cf.id.to_s == match[:id] }
if custom_field
yield custom_field
end
diff --git a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
index daa71e7ca66..bf420ce5ad1 100644
--- a/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/projects/project_representer_rendering_spec.rb
@@ -39,6 +39,7 @@ RSpec.describe API::V3::Projects::ProjectRepresenter, "rendering" do
parent: parent_project,
description: "some description").tap do |p|
allow(p).to receive_messages(available_custom_fields: [int_custom_field, version_custom_field],
+ all_available_custom_fields: [int_custom_field, version_custom_field],
ancestors_from_root: ancestors)
allow(p)