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: pass `query` and `timestamps` to the `WorkPackageCollectionRepresenter`
Sebastian Fiedlschuster17db827554f1
diff --git a/app/services/api/v3/work_package_collection_from_query_service.rb b/app/services/api/v3/work_package_collection_from_query_service.rbindex f6e88fbfb65..f5a78ccb3b1 100644--- a/app/services/api/v3/work_package_collection_from_query_service.rb+++ b/app/services/api/v3/work_package_collection_from_query_service.rb@@ -167,7 +167,9 @@ module APIgroups:,total_sums: sums,embed_schemas: true,- current_user:+ current_user:,+ timestamps: query.timestamps,+ _query: query)endenddiff --git a/lib/api/v3/work_packages/work_package_collection_representer.rb b/lib/api/v3/work_packages/work_package_collection_representer.rbindex 46800f0d943..cd716cdd259 100644--- a/lib/api/v3/work_packages/work_package_collection_representer.rb+++ b/lib/api/v3/work_packages/work_package_collection_representer.rb@@ -30,6 +30,8 @@ module APImodule V3module WorkPackagesclass WorkPackageCollectionRepresenter < ::API::Decorators::OffsetPaginatedCollection+ attr_accessor :timestamps, :_query+def initialize(models,self_link:,groups:,@@ -39,10 +41,14 @@ module APIproject: nil,page: nil,per_page: nil,- embed_schemas: false)+ embed_schemas: false,+ timestamps: [],+ _query: nil)@project = project@total_sums = total_sums@embed_schemas = embed_schemas+ @timestamps = timestamps+ @_query = _querysuper(models,self_link:,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.rbindex 3275d63920e..76af1feab5e 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@@ -45,6 +45,8 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter dolet(:default_page_size) { 30 }let(:total) { 5 }let(:embed_schemas) { false }+ let(:timestamps) { nil }+ let(:_query) { nil }let(:representer) dodescribed_class.new(@@ -57,7 +59,9 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter dopage: page_parameter,per_page: page_size_parameter,current_user: user,- embed_schemas:+ embed_schemas:,+ timestamps:,+ _query:)endlet(:collection_inner_type) { 'WorkPackage' }@@ -469,4 +473,60 @@ describe ::API::V3::WorkPackages::WorkPackageCollectionRepresenter do.at_path('_embedded/schemas/_embedded/elements/0/_links/self/href')endend++ context 'when passing timestamps' do+ let(:work_pacakges) { WorkPackage.where(id: work_package.id) }+ let(:work_package) do+ new_work_package = create(:work_package, subject: "The current work package")+ new_work_package.update_columns created_at: baseline_time - 1.day+ new_work_package+ end+ let(:original_journal) do+ create_journal(journable: work_package, timestamp: baseline_time - 1.day,+ version: 1,+ attributes: { subject: "The original work package" })+ end+ let(:current_journal) do+ create_journal(journable: work_package, timestamp: 1.day.ago,+ version: 2,+ attributes: { subject: "The current work package" })+ end+ let(:baseline_time) { "2022-01-01".to_time }++ def create_journal(journable:, version:, timestamp:, attributes: {})+ work_package_attributes = work_package.attributes.except("id")+ journal_attributes = work_package_attributes \+ .extract!(*Journal::WorkPackageJournal.attribute_names) \+ .symbolize_keys.merge(attributes)+ create(:work_package_journal, version:,+ journable:, created_at: timestamp, updated_at: timestamp,+ data: build(:journal_work_package_journal, journal_attributes))+ end++ before do+ WorkPackage.destroy_all+ work_package+ Journal.destroy_all+ original_journal+ current_journal+ end++ shared_examples_for 'includes the properties of the current work package' do+ it 'includes the properties of the current work package' do+ expect(collection)+ .to be_json_eql("The current work package".to_json)+ .at_path('_embedded/elements/0/subject')+ end+ end++ context 'current only' do+ let(:timestamps) { [Timestamp.parse("PT0S")] }+ it_behaves_like 'includes the properties of the current work package'+ end++ context 'empty' do+ let(:timestamps) { [] }+ it_behaves_like 'includes the properties of the current work package'+ end+ endenddiff --git a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb b/spec/services/api/v3/work_package_collection_from_query_service_spec.rbindex 2d00fa9c035..fff79363b41 100644--- a/spec/services/api/v3/work_package_collection_from_query_service_spec.rb+++ b/spec/services/api/v3/work_package_collection_from_query_service_spec.rb@@ -84,7 +84,9 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,:page,:per_page,:embed_schemas,- :current_user) do+ :current_user,+ :timestamps,+ :_query) dodef initialize(work_packages,self_link:,query:,@@ -94,7 +96,9 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,page:,per_page:,embed_schemas:,- current_user:)+ current_user:,+ timestamps:,+ _query:)super(work_packages,self_link,query,@@ -104,7 +108,9 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,page,per_page,embed_schemas,- current_user)+ current_user,+ timestamps,+ _query)endendend@@ -229,6 +235,25 @@ describe ::API::V3::WorkPackageCollectionFromQueryService,endend+ context 'timestamps' do+ let(:timestamps) { [Timestamp.parse("P-1Y"), Timestamp.now] }+ let(:query) { build_stubbed(:query, timestamps: timestamps) }++ it 'has the query timestamps' do+ expect(subject.timestamps)+ .to match_array(timestamps)+ end+ end++ context '_query' do+ # This is a workaround to allow the representer to access the query object itself.+ # The attribute 'query' is already used by the representer and holds a Hash.+ it 'has the query' do+ expect(subject._query)+ .to eq(query)+ end+ end+context 'total_sums' docontext 'with query.display_sums? being false' doit 'is nil' do