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

Merge branch 'dev' into implementation/45980-improve-performance-of-baseline-filtering

ulferts8bda27589946
diff --cc app/models/journable/historic_active_record_relation.rb
index f1d31c2cb0f,26946cc06c7..7db4d313d74
--- a/app/models/journable/historic_active_record_relation.rb
+++ b/app/models/journable/historic_active_record_relation.rb
@@@ -316,7 -311,8 +316,8 @@@ class Journable::HistoricActiveRecordRe
"journals.journable_id as id",
"journables.created_at as created_at",
"journals.updated_at as updated_at",
- "CASE #{timestamp_case_when_statements} END as timestamp"
- "'#{timestamp}' as timestamp",
++ "CASE #{timestamp_case_when_statements} END as timestamp",
+ "journals.id as journal_id"
] + \
model.column_names_missing_in_journal.collect do |missing_column_name|
"null as #{missing_column_name}"
diff --cc app/models/journable/timestamps.rb
index 56c03174af2,2269f8513fa..9030cd340a9
--- a/app/models/journable/timestamps.rb
+++ b/app/models/journable/timestamps.rb
@@@ -122,6 -124,6 +124,6 @@@ module Journable::Timestamp
def rollback!
raise ActiveRecord::RecordNotSaved, "This is no historic data. You can only revert to historic data." unless historic?
- self.class.find(id).update! attributes.except("id", "timestamp", "created_at", "updated_at")
- self.class.find(id).update! attributes.except("id", "timestamp", "journal_id")
++ self.class.find(id).update! attributes.except("id", "timestamp", "journal_id", "created_at", "updated_at")
end
end
diff --cc app/models/journable/with_historic_attributes.rb
index 0d638eafc36,691cca44cf0..30b307839c2
--- a/app/models/journable/with_historic_attributes.rb
+++ b/app/models/journable/with_historic_attributes.rb
@@@ -118,6 -118,6 +118,10 @@@ class Journable::WithHistoricAttribute
end
end
++ def load_custom_values(journalized)
++ Loader.new(journalized).load_custom_values
++ end
++
private
def wrap_each_journable(journables, timestamps:, query:, include_only_changed_attributes:)
diff --cc spec/models/journable/timestamps_spec.rb
index 3401dac8ab0,96ea7eaa049..cc905cbe045
--- a/spec/models/journable/timestamps_spec.rb
+++ b/spec/models/journable/timestamps_spec.rb
@@@ -38,15 -38,11 +38,17 @@@ RSpec.describe Journable::Timestamps d
let(:thursday) { "2022-08-04".to_datetime }
let(:friday) { "2022-08-05".to_datetime }
+ let(:project) { create(:project_with_types) }
let!(:work_package) do
- new_work_package = create(:work_package, description: "The work package as it is since Friday", estimated_hours: 10, project:)
- new_work_package.update_columns created_at: monday
- new_work_package
+ create(:work_package,
+ description: "The work package as it is since Friday",
+ estimated_hours: 10,
++ project:,
+ journals: {
+ monday => { description: "The work package as it has been on Monday", estimated_hours: 5 },
+ wednesday => { description: "The work package as it has been on Wednesday", estimated_hours: 10 },
+ friday => { description: "The work package as it is since Friday", estimated_hours: 15 }
+ })
end
let(:journable) { work_package }
@@@ -606,6 -589,36 +608,27 @@@
expect(subject.send(column_name)).to eq 0
end
end
+
+ context 'with a custom field present' do
+ let!(:custom_field) do
+ create(:string_wp_custom_field,
+ name: 'String CF',
+ types: project.types,
+ projects: [project])
+ end
+
- let!(:custom_value) do
- create(:custom_value,
- custom_field:,
- customized: work_package,
- value: 'The custom field as it is since Friday')
- end
-
+ let!(:monday_customizable_journal) do
+ create(:journal_customizable_journal,
+ journal: monday_journal,
+ custom_field:,
+ value: 'The custom field as it has been on Monday')
+ end
+
+ it 'loads the custom_values relation with the historic values' do
+ expect(subject.send("custom_field_#{custom_field.id}"))
+ .to eq 'The custom field as it has been on Monday'
- expect(journable.send("custom_field_#{custom_field.id}"))
- .to eq 'The custom field as it is since Friday'
+ end
+ end
end
end
diff --cc spec/requests/api/v3/work_packages/index_resource_spec.rb
index b8aef340426,9714050ed6f..cbbdd11b839
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@@ -250,19 -250,66 +250,41 @@@ RSpec.describe 'API v3 Work package res
let(:baseline_time) { timestamps.first.to_time }
let(:created_at) { baseline_time - 1.day }
- let(:work_package) do
- new_work_package = create(:work_package,
- subject: "The current work package",
- assigned_to: current_user,
- project:)
- new_work_package.update_columns(created_at:)
- new_work_package
+ let!(:work_package) do
+ create(:work_package,
+ created_at:,
+ subject: "The current work package",
+ assigned_to: current_user,
+ project:,
+ journals: {
+ created_at => { subject: "The original work package" },
+ 1.day.ago => {}
+ })
end
+
+ let(:custom_field) do
+ create(:string_wp_custom_field,
+ name: 'String CF',
+ types: project.types,
+ projects: [project])
+ end
+
+ let(:custom_value) do
+ create(:custom_value,
+ custom_field:,
+ customized: work_package,
+ value: 'This the current value')
+ end
+
- let(:original_journal) do
- create_journal(journable: work_package, timestamp: created_at,
- version: 1,
- attributes: { subject: "The original work package",
- assigned_to: current_user,
- project: })
- end
- let(:current_journal) do
- create_journal(journable: work_package, timestamp: 1.day.ago,
- version: 2,
- attributes: { subject: "The current work package",
- assigned_to: current_user,
- project: })
- end
-
- 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
-
+ def create_customizable_journal(journal:, custom_field:, value:)
+ create(:journal_customizable_journal,
+ journal:,
+ custom_field:,
+ value:)
+ end
+
- before do
- work_package.journals.destroy_all
- original_journal
- current_journal
- end
+ let(:original_journal) { work_package.journals.first }
+ let(:current_journal) { work_package.journals.last }
it 'succeeds' do
expect(subject.status).to be 200