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

Fix copying symbolized filters in widgets

Oliver Günther38bebe2ba841
diff --git a/app/services/queries/copy/filters_mapper.rb b/app/services/queries/copy/filters_mapper.rb
index ec61294c832..db41e9b8e0f 100644
--- a/app/services/queries/copy/filters_mapper.rb
+++ b/app/services/queries/copy/filters_mapper.rb
@@ -40,15 +40,15 @@ module Queries::Copy
# Returns the mapped filter array for either
# hash-based APIv3 filters or filter clasess
def map_filters!
- filters.each do |filter|
- if filter.is_a?(Hash)
- map_api_filter_hash(filter)
+ filters.map do |input|
+ if input.is_a?(Hash)
+ filter = input.dup.with_indifferent_access
+ filter.tap(&method(:map_api_filter_hash))
else
- map_filter_class(filter)
+ map_filter_class(input)
+ input
end
end
-
- filters
end
protected
diff --git a/spec/services/queries/filter_mappper_spec.rb b/spec/services/queries/filter_mappper_spec.rb
index ebd6e8d6790..2b87228b906 100644
--- a/spec/services/queries/filter_mappper_spec.rb
+++ b/spec/services/queries/filter_mappper_spec.rb
@@ -98,4 +98,24 @@ describe Queries::Copy::FiltersMapper do
end
end
end
+
+ describe 'with a symbolized filter hash array' do
+ let(:filters) do
+ [
+ { parent: { operator: '=', values: ['1'] } }
+ ]
+ end
+
+ context 'when mapping state exists' do
+ before do
+ state.work_package_id_lookup = { 1 => 11 }
+ state.category_id_lookup = { 2 => 22 }
+ state.version_id_lookup = { 3 => 33 }
+ end
+
+ it 'maps the filters' do
+ expect(subject[0]['parent']['values']).to eq(['11'])
+ end
+ end
+ end
end