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

Add all_available_custom_fields method comment.

Dombi Attilaaa7c2eed5d9f
diff --git a/app/models/projects/custom_fields.rb b/app/models/projects/custom_fields.rb
index 1b6c92bacaf..2bbac410817 100644
--- a/app/models/projects/custom_fields.rb
+++ b/app/models/projects/custom_fields.rb
@@ -37,9 +37,6 @@ module Projects::CustomFields
has_many :project_custom_fields, through: :project_custom_field_project_mappings, class_name: "ProjectCustomField"
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
visible_fields = all_available_custom_fields.visible
return visible_fields if new_record?
@@ -47,6 +44,15 @@ module Projects::CustomFields
.or(ProjectCustomField.required)
end
+ # Note:
+ #
+ # The UI allows the enabled attributes only via the project_custom_field_project_mappings.
+ # The API still provides the old behaviour where all the custom fields are available regardless
+ # of the enabled mapping. Once the api behaviour is aligned to the UI behaviour, this method
+ # can be removed in favour of the available_custom_fields.
+ # As a future improvement a flag `via_api=true` can be set on the project when the
+ # modification happens via the api, then set the available_custom_fields accordingly. This allows
+ # the extension to be completely removed from the acts_as_customizable plugin.
def all_available_custom_fields
@all_available_custom_fields ||= ProjectCustomField
.includes(:project_custom_field_section)
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 a9131efd084..adb8e4c4bcf 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,14 @@ module Redmine
self.class.available_custom_fields(self)
end
+ # Note:
+ #
+ # The role of this method is to provide flexibility on enabling just a subset of
+ # available_custom_fields on the UI while enabling all_available_custom_fields via the api.
+ # A good example is the Project's attributes, the UI allows the enabled attributes only,
+ # and the Projects API still provides the old behaviour where all the custom fields are available.
+ # Once the api behaviour is aligned to the UI behaviour, this method can be removed in favor of
+ # the available_custom_fields method.
def all_available_custom_fields
@all_available_custom_fields ||= available_custom_fields
end