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

adapt behaviour when not providing a query_id

ulferts4fb2c6e0e184
diff --git a/app/controllers/projects/menus_controller.rb b/app/controllers/projects/menus_controller.rb
index e241481618c..b237848997d 100644
--- a/app/controllers/projects/menus_controller.rb
+++ b/app/controllers/projects/menus_controller.rb
@@ -48,7 +48,7 @@ module Projects
def 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 Projects
id.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'
end
end
end
diff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rb
index 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_login
before_action :find_query, only: :destroy
def 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 < ApplicationController
private
- # 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])
end
diff --git a/app/controllers/projects/query_loading.rb b/app/controllers/projects/query_loading.rb
new file mode 100644
index 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
+end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index e329c0607cd..1a77a2adaa8 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -39,6 +39,7 @@ class ProjectsController < ApplicationController
include PaginationHelper
include QueriesHelper
include ProjectsHelper
+ include Projects::QueryLoading
helper_method :has_managed_project_folders?
@@ -47,17 +48,15 @@ class ProjectsController < ApplicationController
end
def 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 @query
respond_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 = nil
end
- 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.rb
index 94df0db7269..388171aac71 100644
--- a/app/models/queries/projects/factory.rb
+++ b/app/models/queries/projects/factory.rb
@@ -34,7 +34,7 @@ class Queries::Projects::Factory
def static_query(id)
case id
- when nil, 'all'
+ when 'all'
static_query_all
when 'my'
static_query_my
diff --git a/app/services/params_to_query_service.rb b/app/services/params_to_query_service.rb
index 596414ff5bb..b986b852082 100644
--- a/app/services/params_to_query_service.rb
+++ b/app/services/params_to_query_service.rb
@@ -49,7 +49,7 @@ class ParamsToQueryService
private
def find_query(query_id)
- if query_factory_class
+ if query_factory_class && query_id
query_factory_class.find(query_id)
elsif query_class.respond_to?(:find) && query_id
query_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.rb
index 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::ProjectQuery
end
- 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_empty
end
- 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_empty
end
end
@@ -83,19 +83,19 @@ RSpec.describe ParamsToQueryService, 'project query' do
.to be_a Queries::Projects::ProjectQuery
end
- it 'sets the expected name' do
+ it 'sets no name' do
expect(service_call.name)
- .to eql I18n.t(:'projects.sidemenu.all')
+ .to be_blank
end
- 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_empty
end
- 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_empty
end
end
end