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
Fix serialization of project query by adding mixin
Oliver Günther83bd71d085d0
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex 96828c331da..5393a2ac683 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -156,7 +156,7 @@ class ProjectsController < ApplicationControllerexport: Projects::Export.create,user: current_user,mime_type: mime_type,- query: Marshal.dump(@query)+ query: @query.to_hash)if request.headers['Accept']&.include?('application/json')diff --git a/app/models/queries/projects/project_query.rb b/app/models/queries/projects/project_query.rbindex 61e47d9afdf..c549a676b93 100644--- a/app/models/queries/projects/project_query.rb+++ b/app/models/queries/projects/project_query.rb@@ -27,6 +27,8 @@#++class Queries::Projects::ProjectQuery < Queries::BaseQuery+ include Queries::Serialization::Hash+def self.modelProjectenddiff --git a/app/models/queries/serialization/hash.rb b/app/models/queries/serialization/hash.rbnew file mode 100644index 00000000000..a894691b8fe--- /dev/null+++ b/app/models/queries/serialization/hash.rb@@ -0,0 +1,60 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Queries+ module Serialization+ module Hash+ extend ActiveSupport::Concern++ class_methods do+ def from_hash(hash)+ new(user: hash[:user]).tap do |query|+ query.add_filters hash[:filters] if hash[:filters].present?+ query.order hash[:orders] if hash[:orders].present?+ query.group hash[:group_by] if hash[:group_by].present?+ end+ end+ end++ def to_hash+ {+ filters: filters.map { |f| { name: f.name, operator: f.operator, values: f.values } },+ orders: orders.to_h { |o| [o.attribute, o.direction] },+ group_by: group_by,+ user: user+ }+ end++ def add_filters(filters)+ filters.each do |f|+ where(f[:name], f[:operator], f[:values])+ end+ end+ end+ end+enddiff --git a/app/views/projects/_project_export_modal.html.erb b/app/views/projects/_project_export_modal.html.erbindex 41fc9cf4862..ab0b944a0d4 100644--- a/app/views/projects/_project_export_modal.html.erb+++ b/app/views/projects/_project_export_modal.html.erb@@ -45,7 +45,8 @@ See COPYRIGHT and LICENSE files for more details.<ul class="op-export-options"><% supported_export_formats.each do |key| %><li class="op-export-options--option">- <%= link_to url_for(action: 'index', format: key),+ <% filter_params = safe_query_params ['filters'] %>+ <%= link_to url_for(action: 'index', format: key, **filter_params),class: 'op-export-options--option-link' do %><%= op_icon("icon-big icon-export-#{key}") %><span class="op-export-options--option-label"><%= t("export.format.#{key}") %></span>diff --git a/app/workers/projects/export_job.rb b/app/workers/projects/export_job.rbindex 26541e51406..28d4ebb012c 100644--- a/app/workers/projects/export_job.rb+++ b/app/workers/projects/export_job.rb@@ -7,7 +7,7 @@ module Projectsprivatedef prepare!- self.query = Marshal.load(query)+ self.query = ::Queries::Projects::ProjectQuery.from_hash(query)endendenddiff --git a/spec/features/projects/export_spec.rb b/spec/features/projects/export_spec.rbindex 057b011a42c..4143fe57f51 100644--- a/spec/features/projects/export_spec.rb+++ b/spec/features/projects/export_spec.rb@@ -30,8 +30,8 @@ require 'spec_helper'require 'features/work_packages/work_packages_page'describe 'project export', type: :feature, js: true do- shared_let(:project1) { FactoryBot.create :project }- shared_let(:project2) { FactoryBot.create :project }+ shared_let(:important_project) { FactoryBot.create :project, name: 'Important schedule plan' }+ shared_let(:party_project) { FactoryBot.create :project, name: 'Christmas party' }shared_let(:admin) { FactoryBot.create :admin }let(:index_page) { ::Pages::Projects::Index.new }@@ -75,11 +75,34 @@ describe 'project export', type: :feature, js: true dolet(:export_type) { 'CSV' }it 'exports the visible projects' do- expect(page).to have_selector('td.name', text: project1.name)+ expect(page).to have_selector('td.name', text: important_project.name)export!- expect(subject).to have_text(project1.name)+ expect(subject).to have_text(important_project.name)+ end++ context 'with a filter set to match only one project' do+ it 'exports with that filter' do+ expect(page).to have_text(important_project.name)+ expect(page).to have_text(party_project.name)++ index_page.open_filters++ index_page.set_filter('name_and_identifier',+ 'Name or identifier',+ 'contains',+ ['Important'])++ click_on 'Apply'+ expect(page).to have_text(important_project.name)+ expect(page).to have_no_text(party_project.name)++ export!++ expect(subject).to have_text(important_project.name)+ expect(subject).not_to have_text(party_project.name)+ endendendenddiff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rbindex a11fcc2995b..25bc1b9f6e2 100644--- a/spec/support/pages/projects/index.rb+++ b/spec/support/pages/projects/index.rb@@ -125,7 +125,10 @@ module Pagesenddef open_filters- click_button('Show/hide filters')+ retry_block do+ click_button('Show/hide filters')+ page.find_field('Add filter', visible: true)+ endenddef click_more_menu_item(item)