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

fixup! [#47064] Support custom_field_* in the attributesByTimestamp

Dombi Attila27313f93fee9
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 4036916eac9..fdd48083ada 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,10 +54,12 @@ module API
parent
].freeze
- # Support custom values and custom fields in the allow list
+ SUPPORTED_CUSTOM_PROPERTIES = [/^custom_field_\d+$/].freeze
SUPPORTED_PROPERTIES = (SUPPORTED_NON_LINK_PROPERTIES + SUPPORTED_LINK_PROPERTIES).freeze
+ ALL_SUPPORTED_PROPERTIES = (SUPPORTED_PROPERTIES + SUPPORTED_CUSTOM_PROPERTIES).freeze
+
STATIC_NON_LINK_PROPERTIES = %w[_meta].freeze
STATIC_LINK_PROPERTIES = ['links', :schema, :self].freeze
@@ -72,9 +74,7 @@ module API
private
def representable_map(*)
- Representable::Binding::Map.new(super.select do |bind|
- rendered_properties.include?(bind.name) || bind.name.starts_with?("custom_field_")
- end)
+ Representable::Binding::Map.new(super.select { |bind| rendered_properties.include?(bind.name) })
end
def compile_links_for(configs, *args)
@@ -84,7 +84,7 @@ module API
def rendered_properties
@rendered_properties ||= begin
- properties = changed_properties_as_api_name.intersection(SUPPORTED_PROPERTIES) + STATIC_NON_LINK_PROPERTIES
+ properties = changed_properties_as_api_name.select(&method(:property_supported?)) + STATIC_NON_LINK_PROPERTIES
if represented.exists_at_timestamp?
properties + STATIC_LINK_PROPERTIES
@@ -114,6 +114,10 @@ module API
SUPPORTED_PROPERTIES
end
end
+
+ def property_supported?(property)
+ ALL_SUPPORTED_PROPERTIES.any? { _1.is_a?(Regexp) ? property =~ _1 : property == _1 }
+ end
end
end
end
diff --git a/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb b/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb
index 932aa8b1cb6..e88059b1f39 100644
--- a/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_at_timestamp_representer_rendering_spec.rb
@@ -56,15 +56,18 @@ RSpec.describe API::V3::WorkPackages::WorkPackageAtTimestampRepresenter, 'render
end
let(:project) { build_stubbed(:project) }
let(:custom_field) do
- build_stubbed(:text_wp_custom_field,
- name: 'Text CF',
+ build_stubbed(:string_wp_custom_field,
+ name: 'String CF',
types: project.types,
projects: [project])
end
let(:available_custom_fields) { [custom_field] }
-
- let(:custom_values) { { custom_field.id => 'This is a text value' } }
+ let(:custom_value) do
+ build_stubbed(:custom_value,
+ custom_field:,
+ value: 'This is a string value')
+ end
let(:work_package) do
build_stubbed(:work_package,
@@ -77,8 +80,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageAtTimestampRepresenter, 'render
priority:,
version:,
parent:,
- responsible:,
- custom_values:).tap do |wp|
+ responsible:).tap do |wp|
allow(wp)
.to receive(:respond_to?)
.and_call_original
@@ -89,11 +91,14 @@ RSpec.describe API::V3::WorkPackages::WorkPackageAtTimestampRepresenter, 'render
allow(wp)
.to receive(:available_custom_fields)
.and_return(available_custom_fields)
+ allow(wp)
+ .to receive(:custom_field_values)
+ .and_return([custom_value])
end
end
let(:timestamp) { Timestamp.new(1.day.ago) }
- let(:attributes_changed_to_baseline) { work_package.attributes.keys }
+ let(:attributes_changed_to_baseline) { work_package.attributes.keys + ["custom_field_#{custom_field.id}"] }
let(:exists_at_timestamp) { true }
let(:with_query) { true }
let(:matches_filters_at_timestamp) { true }
@@ -135,7 +140,7 @@ RSpec.describe API::V3::WorkPackages::WorkPackageAtTimestampRepresenter, 'render
'subject' => work_package.subject,
'startDate' => work_package.start_date,
'dueDate' => work_package.due_date,
- "customField#{custom_field.id}" => 'This is a text value',
+ "customField#{custom_field.id}" => 'This is a string value',
'_meta' => {
'matchesFilters' => true,
'exists' => true,