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: don't include timestamps in links when only `Timestamp.now` is queried

Sebastian Fiedlschuster9fdc2ad26b81
diff --git a/app/models/timestamp.rb b/app/models/timestamp.rb
index 92757eabf0a..b5e9414a71a 100644
--- a/app/models/timestamp.rb
+++ b/app/models/timestamp.rb
@@ -118,7 +118,14 @@ class Timestamp
end
def ==(other)
- iso8601 == other.iso8601
+ case other
+ when String
+ iso8601 == other or to_s == other
+ when Timestamp
+ iso8601 == other.iso8601
+ else
+ raise Timestamp::Exception, "Comparison to #{other.class.name} not implemented, yet."
+ end
end
def eql?(other)
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 7ac17647d60..81460d79b07 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -485,8 +485,9 @@ module API
resources :work_package, except: :schema
def self.work_package(id, timestamps: nil)
- "#{root}/work_packages/#{id}" + if timestamps.present?
- "?" + {timestamps: timestamps_to_param_value(timestamps)}.to_query
+ "#{root}/work_packages/#{id}" + \
+ if (param_value = timestamps_to_param_value(timestamps)).present?
+ "?" + {timestamps: param_value}.to_query
end.to_s
end
@@ -543,8 +544,9 @@ module API
end
def self.timestamps_to_param_value(timestamps)
+ timestamps = Timestamp.parse_multiple(timestamps) if timestamps.is_a? String
timestamps = [timestamps] if timestamps.is_a? Timestamp
- if timestamps.present? and timestamps.kind_of? Array
+ if timestamps.present? and timestamps.kind_of? Array and timestamps != [Timestamp.now]
timestamps.collect { |timestamp| timestamp.absolute.iso8601 }.join(",")
end
end
diff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rb
index 93744ea5d51..90a12cdb4a5 100644
--- a/lib/api/v3/work_packages/work_package_collection_representer.rb
+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb
@@ -55,7 +55,9 @@ module 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) if timestamps.present?
+ if timestamps.present? && (timestamps.count > 1 or timestamps.first.historic?)
+ query[:timestamps] ||= API::V3::Utilities::PathHelper::ApiV3Path.timestamps_to_param_value(timestamps)
+ end
super(models,
self_link:,
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index 52e42755872..023fb908e80 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -470,7 +470,7 @@ module API
[timestamp, attributes.to_h.merge({
"_links": {
"self": {
- "href": API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: Timestamp.parse(timestamp.dup))
+ "href": API::V3::Utilities::PathHelper::ApiV3Path.work_package(id, timestamps: timestamp)
}
}
})]
diff --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.rb
index 826903f0ded..754edd87538 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
@@ -91,6 +91,18 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter do
end
end
end
+
+ describe 'when providing only the current timestamp' do
+ let(:timestamps) { [Timestamp.parse("PT0S")] }
+
+ it 'has no timestamps within the self link' do
+ Timecop.freeze do
+ is_expected
+ .not_to include_json("timestamps".to_json)
+ .at_path('_links/self/href')
+ end
+ end
+ end
end
describe 'representations' do
@@ -582,7 +594,12 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter do
context 'current only' do
let(:timestamps) { [Timestamp.parse("PT0S")] }
it_behaves_like 'includes the properties of the current work package'
- it_behaves_like 'has the absolute timestamps within the self link'
+
+ it 'has no timestamps within the self link' do
+ is_expected
+ .not_to include_json("timestamps".to_json)
+ .at_path('_embedded/elements/0/_links/self/href')
+ end
end
context 'baseline only' do