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

baseline api: remove redundant `timestamp` attribute

Sebastian Fiedlschuster222873ca5a6e
diff --git a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
index 6a069e0f981..44b15f3e0ae 100644
--- a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
+++ b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
@@ -35,8 +35,12 @@ module API::V3::WorkPackages::EagerLoading
work_package_array_index = work_packages.map(&:id).find_index(work_package.id)
work_package_with_historic_attributes = work_packages_with_historic_attributes[work_package_array_index]
work_package.attributes = work_package_with_historic_attributes.attributes.try(:except, 'timestamp')
- work_package.baseline_attributes = work_package_with_historic_attributes.baseline_attributes
- work_package.attributes_by_timestamp = work_package_with_historic_attributes.attributes_by_timestamp
+ work_package.baseline_attributes = work_package_with_historic_attributes.baseline_attributes.try(:except, 'timestamp')
+ work_package.attributes_by_timestamp = work_package_with_historic_attributes.attributes_by_timestamp \
+ .transform_values do |attributes|
+ attributes.delete_field('timestamp') if attributes.respond_to? :timestamp
+ attributes
+ end
work_package.timestamps = work_package_with_historic_attributes.timestamps
work_package.baseline_timestamp = work_package_with_historic_attributes.baseline_timestamp
work_package.matches_query_filters_at_baseline_timestamp = \
diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rb
index b0e07c14482..4e7f7d9ae2e 100644
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@ -325,6 +325,20 @@ describe 'API v3 Work package resource',
end
end
+ it 'has no redundant timestamp attribute in the main section' do
+ # The historic work packages have a timestamp attribute. But we do not expose that here
+ # because the timestamp is already given in the _meta section.
+ expect(subject.body)
+ .not_to have_json_path("_embedded/elements/0/timestamp")
+ end
+
+ it 'has no redundant timestamp attribute in the attributesByTimestamp' do
+ # The historic work packages have a timestamp attribute. But we do not expose that here
+ # because the timestamp is already given in the _meta section.
+ expect(subject.body)
+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/timestamp")
+ end
+
describe "when filtering such that the filters do not match at all timestamps" do
let(:path) { api_v3_paths.path_for :work_packages, filters:, timestamps: }
let(:filters) do