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

remove available_custom_fields override from AttributesByTimestampWorkPackage

ulferts571bcf22552a
diff --git a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
index 9f1df3efb2a..57aaf4d47cd 100644
--- a/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
+++ b/lib/api/v3/work_packages/eager_loading/historic_attributes.rb
@@ -158,15 +158,5 @@ module API::V3::WorkPackages::EagerLoading
def timestamp
new_record? ? @timestamp : Timestamp.parse(__getobj__.timestamp)
end
-
- def available_custom_fields
- # The Journable::WithHistoricAttributes#load_custom_values loads the historic
- # Journal::CustomizableJournal objects and they are being dubbed as custom values.
- # The custom_values contain only the historic Journal::CustomizableJournal objects
- # that were available on the WorkPackage at the timestamp we are looking at.
- # The intersection is made with the super to filter out any historic custom fields that
- # are not activated for the work package.
- @available_custom_fields ||= super.intersection(custom_values.map(&:custom_field))
- end
end
end
diff --git a/spec/requests/api/v3/work_packages/index_resource_spec.rb b/spec/requests/api/v3/work_packages/index_resource_spec.rb
index 1d2ad67e7ef..e1c821401c5 100644
--- a/spec/requests/api/v3/work_packages/index_resource_spec.rb
+++ b/spec/requests/api/v3/work_packages/index_resource_spec.rb
@@ -298,40 +298,6 @@ RSpec.describe 'API v3 Work package resource',
.to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")
end
- context 'when the custom fields are changed' do
- before do
- custom_field
- custom_value
- create_customizable_journal(journal: original_journal, custom_field:, value: 'Original value')
- end
-
- it 'embeds the custom fields in the attributesByTimestamp' do
- expect(subject.body)
- .to be_json_eql('Original value'.to_json)
- .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")
- expect(subject.body)
- .to be_json_eql('This the current value'.to_json)
- .at_path("_embedded/elements/0/customField#{custom_field.id}")
- expect(subject.body)
- .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")
- end
-
- context 'and the custom field is deactivated in the meantime' do
- before do
- custom_field.destroy
- end
-
- it 'does not embeds the custom fields in the attributesByTimestamp' do
- expect(subject.body)
- .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")
- expect(subject.body)
- .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0")
- expect(subject.body)
- .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")
- end
- end
- end
-
it 'does not embed the attributes in attributesByTimestamp if they are the same as the current attributes' do
expect(subject.body)
.not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1/description")
@@ -393,6 +359,96 @@ RSpec.describe 'API v3 Work package resource',
.at_path('_embedded/elements/0/_meta/timestamp')
end
+ context 'when a custom value changes' do
+ before do
+ custom_value
+ create_customizable_journal(journal: original_journal, custom_field:, value: 'Original value')
+ create_customizable_journal(journal: current_journal, custom_field:, value: custom_value.value)
+ end
+
+ it 'embeds the custom fields in the attributesByTimestamp' do
+ expect(subject.body)
+ .to be_json_eql('Original value'.to_json)
+ .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")
+ expect(subject.body)
+ .to be_json_eql('This the current value'.to_json)
+ .at_path("_embedded/elements/0/customField#{custom_field.id}")
+ expect(subject.body)
+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")
+ expect(subject.body)
+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1/customField#{custom_field.id}")
+ end
+
+ it 'includes a custom field description in the schema' do
+ expect(subject.body)
+ .to be_json_eql(custom_field.name.to_json)
+ .at_path("_embedded/schemas/_embedded/elements/0/customField#{custom_field.id}/name")
+ end
+ end
+
+ context 'when there is a custom value in the past but not in the now as the custom field has been destroyed' do
+ before do
+ create_customizable_journal(journal: original_journal, custom_field:, value: 'Original value')
+ custom_field.destroy
+ end
+
+ it 'does not embed the custom fields in the attributesByTimestamp' do
+ expect(subject.body)
+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0")
+ expect(subject.body)
+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")
+ expect(subject.body)
+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")
+ expect(subject.body)
+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1/customField#{custom_field.id}")
+ end
+ end
+
+ context 'when there is a custom value now but not in the past' do
+ before do
+ custom_value
+ create_customizable_journal(journal: current_journal, custom_field:, value: custom_value.value)
+ end
+
+ it 'has an empty value in the attributesByTimestamp of the past and no value in the now (since it is the current one)' do
+ expect(subject.body)
+ .to be_json_eql(nil.to_json)
+ .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")
+ expect(subject.body)
+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")
+ expect(subject.body)
+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1/customField#{custom_field.id}")
+ end
+
+ it 'includes a custom field description in the schema' do
+ expect(subject.body)
+ .to be_json_eql(custom_field.name.to_json)
+ .at_path("_embedded/schemas/_embedded/elements/0/customField#{custom_field.id}/name")
+ end
+ end
+
+ context 'when there is a custom value in the past but not now' do
+ before do
+ create_customizable_journal(journal: original_journal, custom_field:, value: 'Original value')
+ end
+
+ it 'embeds the custom fields in the attributesByTimestamp of the past but not in the now' do
+ expect(subject.body)
+ .to be_json_eql('Original value'.to_json)
+ .at_path("_embedded/elements/0/_embedded/attributesByTimestamp/0/customField#{custom_field.id}")
+ expect(subject.body)
+ .to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1")
+ expect(subject.body)
+ .not_to have_json_path("_embedded/elements/0/_embedded/attributesByTimestamp/1/customField#{custom_field.id}")
+ end
+
+ it 'includes a custom field description in the schema' do
+ expect(subject.body)
+ .to be_json_eql(custom_field.name.to_json)
+ .at_path("_embedded/schemas/_embedded/elements/0/customField#{custom_field.id}/name")
+ end
+ end
+
describe "when filtering such that the filters do not match at all timestamps" do
let(:path) { api_v3_paths.path_for(:work_packages, filters:, timestamps:) }
let(:filters) do
@@ -676,6 +732,12 @@ RSpec.describe 'API v3 Work package resource',
before do
custom_field
custom_value
+ create_customizable_journal(journal: original_journal,
+ custom_field:,
+ value: custom_value.value)
+ create_customizable_journal(journal: current_journal,
+ custom_field:,
+ value: custom_value.value)
end
it 'has no attributes in the embedded objects because they are the same as in the main object' do