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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
fix wp index without timestamps
ulferts40b9b0f88261
diff --git a/app/models/journable/with_historic_attributes.rb b/app/models/journable/with_historic_attributes.rbindex ce3a3a25099..728861e71e1 100644--- a/app/models/journable/with_historic_attributes.rb+++ b/app/models/journable/with_historic_attributes.rb@@ -97,25 +97,24 @@ class Journable::WithHistoricAttributes < SimpleDelegatorprivate_class_method :newclass << self- def wrap(journable_or_journables, timestamps: nil, query: nil, include_only_changed_attributes: false)+ def wrap(journable_or_journables,+ timestamps: query.try(:timestamps) || [],+ query: nil,+ include_only_changed_attributes: false)+ wrapped = wrap_each_journable(Array(journable_or_journables), timestamps:, query:, include_only_changed_attributes:)+case journable_or_journableswhen Array, ActiveRecord::Relation- wrap_multiple(journable_or_journables, timestamps:, query:, include_only_changed_attributes:)+ wrappedelse- wrap_one(journable_or_journables, timestamps:, query:, include_only_changed_attributes:)+ wrapped.firstendendprivate- def wrap_one(journable, timestamps: nil, query: nil, include_only_changed_attributes: false)- wrap_multiple(Array(journable), timestamps:, query:, include_only_changed_attributes:).first- end-- def wrap_multiple(journables, timestamps: nil, query: nil, include_only_changed_attributes: false)- timestamps ||= query.try(:timestamps) || []+ def wrap_each_journable(journables, timestamps:, query:, include_only_changed_attributes:)loader = Loader.new(journables)-journables = loader.at_timestamp(timestamps.last).values if timestamps.last.try(:historic?)journables.map { |j| new(j, timestamps:, query:, include_only_changed_attributes:, loader:) }diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex 04da611f220..da271e3c5cc 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -490,7 +490,7 @@ module APIdef self.work_package(id, timestamps: nil)"#{root}/work_packages/#{id}" + \- if (param_value = timestamps_to_param_value(timestamps)).present?+ if (param_value = timestamps_to_param_value(timestamps)).present? && Array(timestamps).any?(&:historic?)"?#{{ timestamps: param_value }.to_query}"end.to_senddiff --git a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb b/lib/api/v3/work_packages/eager_loading/historic_attributes.rbindex c8d79c2990d..f02ce94cb5d 100644--- a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb+++ b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb@@ -28,9 +28,12 @@module API::V3::WorkPackages::EagerLoadingclass HistoricAttributes < Base- attr_accessor :timestamps, :query+ attr_writer :timestamps+ attr_accessor :querydef apply(work_package)+ return unless timestamps.any?(&:historic?)+work_package_with_historic_attributes = work_packages_with_historic_attributes[work_package.id]set_non_delegated_properties(work_package,@@ -40,9 +43,8 @@ module API::V3::WorkPackages::EagerLoadingwork_package.at_timestamps = work_package_with_historic_attributes.timestamps.map do |timestamp|- wrapped_wp = HistoricAttributesDelegator- .new(work_package_with_historic_attributes.at_timestamp(timestamp))- wrapped_wp.timestamp = timestamp.dup+ wrapped_wp = AttributesByTimestampWorkPackage+ .new(work_package_with_historic_attributes.at_timestamp(timestamp), timestamp)set_non_delegated_properties(wrapped_wp,work_package_with_historic_attributes,@@ -66,12 +68,16 @@ module API::V3::WorkPackages::EagerLoadingenddef work_packages_with_historic_attributes- @work_packages_with_historic_attributes ||= begin- @timestamps ||= @query.try(:timestamps) || []- Journable::WithHistoricAttributes \- .wrap(work_packages, timestamps: @timestamps, query: @query, include_only_changed_attributes: true)- .index_by(&:id)- end+ @work_packages_with_historic_attributes ||= Journable::WithHistoricAttributes+ .wrap(work_packages,+ timestamps:,+ query:,+ include_only_changed_attributes: true)+ .index_by(&:id)+ end++ def timestamps+ @timestamps ||= query.try(:timestamps) || []endend@@ -96,18 +102,21 @@ module API::V3::WorkPackages::EagerLoadingendend- # TODO: Get this in line with the rest of the eager loading- class HistoricAttributesDelegator < SimpleDelegator+ # The wrapper around a work package only loaded to be then displayed as part of the+ # attributesByTimestamps in the work package representer.+ class AttributesByTimestampWorkPackage < SimpleDelegatorinclude HistoricAttributesAccessors- def initialize(work_package)+ def initialize(work_package, timestamp)super(work_package || WorkPackage.new)++ self.timestamp = timestamp.dupendattr_writer :timestampdef timestamp- new_record? ? @timestamp : __getobj__.timestamp+ new_record? ? @timestamp : Timestamp.parse(__getobj__.timestamp)end# Since custom fields are currently never displayed in the attributesByTimestamp,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.rbindex e55192f0bae..da51fc6481e 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@@ -58,6 +58,10 @@ module APIsuper(model, current_user:, embed_links:, timestamps: [model.timestamp])end+ def timestamps_active?+ true+ end+privatedef representable_map(*)diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex 3523f8b66b1..d75d170772e 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -676,7 +676,7 @@ module APIenddef timestamps_active?- timestamps.any?+ timestamps.any?(&:historic?)end# Attachments need to be eager loaded for the descriptiondiff --git a/spec/lib/api/v3/utilities/path_helper_spec.rb b/spec/lib/api/v3/utilities/path_helper_spec.rbindex a1fadf1f73d..a677a012735 100644--- a/spec/lib/api/v3/utilities/path_helper_spec.rb+++ b/spec/lib/api/v3/utilities/path_helper_spec.rb@@ -531,6 +531,19 @@ describe API::V3::Utilities::PathHelper dodescribe 'work packages paths' doit_behaves_like 'resource', :work_package, except: [:schema]+ # The simple case (with an id) is already covered by the 'it_behaves_like'+ describe '#work_package with an historic timestamp' do+ subject { helper.work_package 42, timestamps: Timestamp.parse("2020-02-02 02:02:02") }++ it_behaves_like 'api v3 path', '/work_packages/42?timestamps=2020-02-02T02%3A02%3A02Z'+ end++ describe '#work_package with a NOW timestamp' do+ subject { helper.work_package 42, timestamps: Timestamp.now }++ it_behaves_like 'api v3 path', '/work_packages/42'+ end+describe '#work_package_activities' dosubject { helper.work_package_activities 42 }diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rbindex 762a34dfde2..75757bee9c0 100644--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb@@ -235,7 +235,7 @@ describe 'API v3 Work package resource',endend- context 'when provoding timestamps' do+ context 'when providing timestamps' dosubject doget pathlast_response