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
[40324] Reduce type form queries to valid subset
Oliver Güntherc610c982c2a5
diff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rbindex 39ee029052b..969957177b3 100644--- a/app/helpers/types_helper.rb+++ b/app/helpers/types_helper.rb@@ -104,10 +104,15 @@ module ::TypesHelperdef query_to_query_props(group)return nil unless group.group_type == :query+ query = group.attributes++ # Reduce the query to its valid subset to avoid errors loading the form+ query.valid_subset!+# Modify the hash to match Rails array based +to_query+ transforms:# e.g., { columns: [1,2] }.to_query == "columns[]=1&columns[]=2" (unescaped)# The frontend will do that IFF the hash key is an array- ::API::V3::Queries::QueryParamsRepresenter.new(group.attributes).to_json+ ::API::V3::Queries::QueryParamsRepresenter.new(query).to_jsonendprivatediff --git a/spec/features/types/form_configuration_query_spec.rb b/spec/features/types/form_configuration_query_spec.rbindex b8e9ed44c4e..ea55d23178a 100644--- a/spec/features/types/form_configuration_query_spec.rb+++ b/spec/features/types/form_configuration_query_spec.rb@@ -28,6 +28,7 @@require 'spec_helper'+# rubocop:disable RSpec/MultipleMemoizedHelpersdescribe 'form query configuration', type: :feature, js: true doshared_let(:admin) { FactoryBot.create :admin }let(:type_bug) { FactoryBot.create :type_bug }@@ -131,6 +132,34 @@ describe 'form query configuration', type: :feature, js: true doendend+ context 'with an archived project' do+ let!(:archived) { FactoryBot.create :project, name: 'To be archived' }++ it 'uses the valid subset of the query (Regression #40324)' do+ form.add_query_group('Archived project', :children)+ form.edit_query_group('Archived project')++ # Select the soon archived project+ modal.switch_to 'Filters'+ filters.expect_filter_count 1+ filters.add_filter_by('Project', 'is', archived.name)+ filters.expect_filter_count 2+ filters.save++ form.save_changes+ expect(page).to have_selector('.flash.notice', text: 'Successful update.', wait: 10)++ archived.update_attribute(:active, false)++ visit edit_type_tab_path(id: type_bug.id, tab: "form_configuration")+ form.edit_query_group('Archived project')++ # Expect we now get the valid subset without the invalid project+ modal.switch_to 'Filters'+ filters.expect_filter_count 1+ end+ end+it 'can modify and keep changed columns (Regression #27604)' doform.add_query_group('Columns Test', :children)form.edit_query_group('Columns Test')@@ -293,3 +322,4 @@ describe 'form query configuration', type: :feature, js: true doendendend+# rubocop:enable RSpec/MultipleMemoizedHelpers