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 rendered_properties_for_links method

Dombi Attila4aa4b9a01f8a
diff --git a/lib/api/v3/work_packages/work_package_at_timestamp_representer.rb b/lib/api/v3/work_packages/work_package_at_timestamp_representer.rb
index 7b342c63f7f..e5cc91ce934 100644
--- a/lib/api/v3/work_packages/work_package_at_timestamp_representer.rb
+++ b/lib/api/v3/work_packages/work_package_at_timestamp_representer.rb
@@ -54,7 +54,7 @@ module API
parent
].freeze
- SUPPORTED_CUSTOM_PROPERTIES = [/^customField\d+$/].freeze
+ SUPPORTED_CUSTOM_PROPERTIES = [/^custom_field_\d+$/].freeze
SUPPORTED_PROPERTIES = (SUPPORTED_NON_LINK_PROPERTIES + SUPPORTED_LINK_PROPERTIES).freeze
@@ -78,7 +78,7 @@ module API
end
def compile_links_for(configs, *args)
- super(configs.select { |config| rendered_properties.include?(config.first[:rel]) },
+ super(configs.select { |config| rendered_properties_for_links.include?(config.first[:rel]) },
*args)
end
@@ -94,6 +94,21 @@ module API
end
end
+ # This separate property list is a workaround and ideally it is not required.
+ # The reason is that names in the representable_map are underscored "custom_fields_1",
+ # the :rel names in the config from the compile_links_for method are lower camel-cased "customField1".
+ # The rendered_properties method contains the underscored names and the rendered_properties_for_links
+ # contains the lower camel-cased names.
+ def rendered_properties_for_links
+ @rendered_properties_for_links ||= rendered_properties.map do |property|
+ if property.starts_with?("custom_field_")
+ API::Utilities::PropertyNameConverter.from_ar_name(property)
+ else
+ property
+ end
+ end
+ end
+
def changed_properties_as_api_name
# This conversion is good enough for the set of supported properties as it
# * Converts assigned_to_id to assignee
@@ -102,7 +117,7 @@ module API
represented
.attributes_changed_to_baseline
.flat_map do |property|
- if property.ends_with?('_id') || property.starts_with?("custom_field_")
+ if property.ends_with?('_id')
API::Utilities::PropertyNameConverter.from_ar_name(property)
elsif %w[start_date due_date].include?(property)
['date', property]