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
baseline api: the work-package-collection self link includes the absolute timestamps
Sebastian Fiedlschustere1ae8eae5ae4
diff --git a/app/models/timestamp.rb b/app/models/timestamp.rbindex e7ce5638d09..92757eabf0a 100644--- a/app/models/timestamp.rb+++ b/app/models/timestamp.rb@@ -89,6 +89,10 @@ class Timestamp"#<Timestamp \"#{iso8601}\">"end+ def absolute+ Timestamp.new(to_time)+ end+def to_timeif relative?Time.zone.now - (to_duration * (to_duration.to_i.positive? ? 1 : -1))diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex d279e050d22..d2866d66cb2 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -536,14 +536,23 @@ module API"#{project(project_id)}/work_packages"end- def self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil, offset: nil, select: nil)+ def self.timestamps_to_param_value(timestamps)+ if timestamps.present? and timestamps.is_a? Array+ timestamps.collect { |timestamp| timestamp.absolute.iso8601 }.join(",")+ end+ end++ def self.path_for(path, filters: nil, sort_by: nil, group_by: nil, page_size: nil, offset: nil, select: nil, timestamps: nil)+ timestamps = timestamps_to_param_value(timestamps)+query_params = {filters: filters&.to_json,sortBy: sort_by&.to_json,groupBy: group_by,pageSize: page_size,offset:,- select:+ select:,+ timestamps:}.compact_blankif query_params.any?diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rbindex fa0ba48d5ff..26c0a2de73c 100644--- a/lib/api/v3/work_packages/work_package_collection_representer.rb+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb@@ -50,6 +50,13 @@ module API@timestamps = timestamps@_query = _query+ # While `_query` is the actual query object, `query` refers to+ # the query parameters passed to the API.+ # TODO: Should we rename `_query` to `query_object`?+ # TODO: Should we rename `query` to `query_params`?+ # TODO: Should we include the timestamps in the query params instead of passing them separately?+ query[:timestamps] ||= API::V3::Utilities::PathHelper::ApiV3Path.timestamps_to_param_value(timestamps)+super(models,self_link:,query:,@@ -71,6 +78,7 @@ module API# and set those to be the represented collection.# A potential ordering is reapplied to the work package collection in ruby.+ # TODO: Should we pass the timestamps only through the `query` rather than passing them separately?@represented = ::API::V3::WorkPackages::WorkPackageEagerLoadingWrapper.wrap(represented, current_user, timestamps:, query: _query)enddiff --git a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rbindex 9258af7ae0c..31200a7f05e 100644--- a/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb+++ b/spec/lib/api/v3/work_packages/work_package_collection_representer_spec.rb@@ -77,6 +77,20 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter dosubject(:collection) { representer.to_json }describe '_links' do+ describe 'self' do+ describe 'when providing timestamps' do+ let(:timestamps) { [Timestamp.parse("2022-01-01T00:00:00Z"), Timestamp.parse("PT0S")] }+ let(:absolute_timestamp_strings) { timestamps.collect { |timestamp| timestamp.absolute.iso8601 } }+ let(:absolute_timestamps_query_param) { { timestamps: absolute_timestamp_strings.join(",") }.to_query }++ it 'has the absolute timestamps within the self link' do+ is_expected+ .to include_json(absolute_timestamps_query_param.to_json)+ .at_path('_links/self/href')+ end+ end+ end+describe 'representations' docontext 'when outside of a project and the user has the export_work_packages permission' dolet(:query) { { foo: 'bar' } }