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
adapt behaviour when not providing a query_id
ulferts4fb2c6e0e184
diff --git a/app/controllers/projects/menus_controller.rb b/app/controllers/projects/menus_controller.rbindex e241481618c..b237848997d 100644--- a/app/controllers/projects/menus_controller.rb+++ b/app/controllers/projects/menus_controller.rb@@ -48,7 +48,7 @@ module Projectsdef static_filters[- query_menu_item(::Queries::Projects::Factory.static_query_all, selected: no_query_props?),+ query_menu_item(::Queries::Projects::Factory.static_query_all, selected: no_query_props_or_all?),query_menu_item(::Queries::Projects::Factory.static_query_my, id: 'my'),query_menu_item(::Queries::Projects::Factory.static_query_archived, id: 'archived')]@@ -79,8 +79,9 @@ module Projectsid.to_s == params[:query_id] && params[:filters].nil?end- def no_query_props?- params[:query_id].nil? && params[:filters].nil?+ def no_query_props_or_all?+ (params[:query_id].nil? && params[:filters].nil?) ||+ params[:query_id] == 'all'endendenddiff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rbindex ba6cee37ea4..21ce9921780 100644--- a/app/controllers/projects/queries_controller.rb+++ b/app/controllers/projects/queries_controller.rb@@ -27,13 +27,16 @@# ++class Projects::QueriesController < ApplicationController+ include Projects::QueryLoading+# No need for a more specific authorization check. That is carried out in the contracts.before_action :require_loginbefore_action :find_query, only: :destroydef create- call = Queries::Projects::ProjectQueries::CreateService.new(user: current_user)- .call(load_query.attributes.merge(name: params[:name]))+ call = Queries::Projects::ProjectQueries::CreateService+ .new(user: current_user)+ .call(load_query.attributes.merge(name: params[:name]))if call.success?redirect_to projects_path(query_id: call.result.id)@@ -55,11 +58,6 @@ class Projects::QueriesController < ApplicationControllerprivate- # TODO: move to module to share with projects_controller- def load_query- ParamsToQueryService.new(Project, current_user).call(params)- end-def find_query@query = Queries::Projects::ProjectQuery.find(params[:id])enddiff --git a/app/controllers/projects/query_loading.rb b/app/controllers/projects/query_loading.rbnew file mode 100644index 00000000000..bfdc90c081c--- /dev/null+++ b/app/controllers/projects/query_loading.rb@@ -0,0 +1,36 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2024 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 Projects+ module QueryLoading+ def load_query+ params[:query_id] ||= 'all'++ ParamsToQueryService.new(Project, current_user).call(params)+ end+ end+enddiff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex e329c0607cd..1a77a2adaa8 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -39,6 +39,7 @@ class ProjectsController < ApplicationControllerinclude PaginationHelperinclude QueriesHelperinclude ProjectsHelper+ include Projects::QueryLoadinghelper_method :has_managed_project_folders?@@ -47,17 +48,15 @@ class ProjectsController < ApplicationControllerenddef index- query = load_query+ @query = load_query- unless query.valid?- flash[:error] = query.errors.full_messages- end-- @projects = load_projects query- @orders = set_sorting query+ @projects = load_projects @query+ @orders = set_sorting @queryrespond_to do |format|format.html do+ flash.now[:error] = @query.errors.full_messages unless @query.valid?+render layout: 'global'end@@ -115,10 +114,6 @@ class ProjectsController < ApplicationController@project = nilend- def load_query- @query = ParamsToQueryService.new(Project, current_user).call(params)- end-def export_list(mime_type)job = Projects::ExportJob.perform_later(export: Projects::Export.create,diff --git a/app/models/queries/projects/factory.rb b/app/models/queries/projects/factory.rbindex 94df0db7269..388171aac71 100644--- a/app/models/queries/projects/factory.rb+++ b/app/models/queries/projects/factory.rb@@ -34,7 +34,7 @@ class Queries::Projects::Factorydef static_query(id)case id- when nil, 'all'+ when 'all'static_query_allwhen 'my'static_query_mydiff --git a/app/services/params_to_query_service.rb b/app/services/params_to_query_service.rbindex 596414ff5bb..b986b852082 100644--- a/app/services/params_to_query_service.rb+++ b/app/services/params_to_query_service.rb@@ -49,7 +49,7 @@ class ParamsToQueryServiceprivatedef find_query(query_id)- if query_factory_class+ if query_factory_class && query_idquery_factory_class.find(query_id)elsif query_class.respond_to?(:find) && query_idquery_class.find(query_id)diff --git a/spec/services/params_to_query_service_project_query_spec.rb b/spec/services/params_to_query_service_project_query_spec.rbindex efdfd3e3adf..69957881771 100644--- a/spec/services/params_to_query_service_project_query_spec.rb+++ b/spec/services/params_to_query_service_project_query_spec.rb@@ -66,14 +66,14 @@ RSpec.describe ParamsToQueryService, 'project query' do.to be_a Queries::Projects::ProjectQueryend- it 'applies the active filter' do- expect(service_call.filters.map { |f| { field: f.field, operator: f.operator, values: f.values } })- .to contain_exactly({ field: :active, operator: "=", values: ["t"] })+ it 'applies no filter' do+ expect(service_call.filters)+ .to be_emptyend- it 'sorts by lft asc' do- expect(service_call.orders.map { |o| { attribute: o.attribute, direction: o.direction } })- .to eql [{ attribute: :lft, direction: :asc }]+ it 'does not apply sorting' do+ expect(service_call.orders)+ .to be_emptyendend@@ -83,19 +83,19 @@ RSpec.describe ParamsToQueryService, 'project query' do.to be_a Queries::Projects::ProjectQueryend- it 'sets the expected name' do+ it 'sets no name' doexpect(service_call.name)- .to eql I18n.t(:'projects.sidemenu.all')+ .to be_blankend- it 'applies the active filter' do- expect(service_call.filters.map { |f| { field: f.field, operator: f.operator, values: f.values } })- .to contain_exactly({ field: :active, operator: "=", values: ["t"] })+ it 'applies no filter' do+ expect(service_call.filters)+ .to be_emptyend- it 'sorts by lft asc' do- expect(service_call.orders.map { |o| { attribute: o.attribute, direction: o.direction } })- .to eql [{ attribute: :lft, direction: :asc }]+ it 'does not apply sorting' do+ expect(service_call.orders)+ .to be_emptyendendend