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: include `_meta/matchesFilters` in the base work package

Sebastian Fiedlschuster79716e53a31d
diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rb
index 8a76da14cd0..dcc7654e9fe 100644
--- a/lib/api/v3/work_packages/work_package_representer.rb
+++ b/lib/api/v3/work_packages/work_package_representer.rb
@@ -326,6 +326,21 @@ module API
end
end
+ property :_meta,
+ if: ->(*) {
+ respond_to? :matches_query_filters_at_timestamps \
+ and matches_query_filters_at_timestamps.any?
+ },
+ getter: ->(*) {
+ {
+ # This meta property states whether the attributes of the work package at the
+ # last given timestamp (commonly the current time) match the filters of the
+ # query. https://github.com/opf/openproject/pull/11783
+ #
+ 'matchesFilters': matches_query_filters_at_timestamp?(attributes_by_timestamp.keys.last)
+ }
+ }
+
property :id,
render_nil: true
diff --git a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
index 85fc820472b..74e13c6acc7 100644
--- a/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/work_package_representer_spec.rb
@@ -1410,6 +1410,15 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
end
end
+ describe '_meta' do
+ describe 'matchesFilters' do
+ it 'does not have this meta field without a query given' do
+ expect(subject)
+ .not_to have_json_path('_meta/matchesFilters')
+ end
+ end
+ end
+
context 'when passing a query' do
let(:search_term) { 'original' }
let(:query) do
@@ -1446,6 +1455,18 @@ describe ::API::V3::WorkPackages::WorkPackageRepresenter do
.at_path("_embedded/attributesByTimestamp/#{timestamps[1]}/_meta/matchesFilters")
end
end
+
+ describe '_meta' do
+ describe 'matchesFilters' do
+ it 'states whether the work package matches the query filters at the last timestamp' do
+ # If this value is false, it means that the work package has been found by the query
+ # at another of the given timestamps, e.g. the baseline timestamp.
+ expect(subject)
+ .to be_json_eql(false.to_json)
+ .at_path('_meta/matchesFilters')
+ end
+ end
+ end
end
end
end