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

query deletion

ulfertse758a2b51dd3
diff --git a/app/components/projects/index_page_header_component.html.erb b/app/components/projects/index_page_header_component.html.erb
index b1cd915420d..e7b42ccb9d9 100644
--- a/app/components/projects/index_page_header_component.html.erb
+++ b/app/components/projects/index_page_header_component.html.erb
@@ -64,6 +64,18 @@
) do |item|
item.with_leading_visual_icon(icon: 'op-file-download')
end
+
+ if query.persisted?
+ menu.with_item(
+ label: t(:button_delete),
+ href: projects_query_path(query),
+ form_arguments: {
+ method: :delete
+ }
+ ) do |item|
+ item.with_leading_visual_icon(icon: 'trash')
+ end
+ end
end
%>
<% end %>
diff --git a/app/controllers/projects/menus_controller.rb b/app/controllers/projects/menus_controller.rb
index ff905ca4b52..3d2f11c984e 100644
--- a/app/controllers/projects/menus_controller.rb
+++ b/app/controllers/projects/menus_controller.rb
@@ -41,7 +41,7 @@ module Projects
[
OpenProject::Menu::MenuGroup.new(header: nil,
children: static_filters),
- OpenProject::Menu::MenuGroup.new(header: I18n.t(:'projects.menu.my_private_lists'),
+ OpenProject::Menu::MenuGroup.new(header: I18n.t(:'projects.sidemenu.my_private_lists'),
children: my_filters)
]
end
diff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rb
index 3f3e30c621e..d29f7f7e201 100644
--- a/app/controllers/projects/queries_controller.rb
+++ b/app/controllers/projects/queries_controller.rb
@@ -27,6 +27,8 @@
# ++
class Projects::QueriesController < ApplicationController
+ before_action :find_query, only: :destroy
+
# TODO authorization
def create
query = load_query
@@ -37,9 +39,20 @@ class Projects::QueriesController < ApplicationController
redirect_to projects_path(query_id: query.id)
end
+ def destroy
+ @query.destroy
+
+ redirect_to projects_path
+ end
+
private
+ # TODO: move to module to share with projects_controller
def load_query
@query = ParamsToQueryService.new(Project, current_user).call(params)
end
+
+ def find_query
+ @query = Queries::Projects::ProjectQuery.find(params[:id])
+ end
end
diff --git a/config/routes.rb b/config/routes.rb
index 07d061f8854..6973ac6dec1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -181,7 +181,7 @@ OpenProject::Application.routes.draw do
namespace :projects do
resource :menu, only: %i[show]
- resources :queries, only: %i[create]
+ resources :queries, only: %i[create destroy]
end
resources :projects, except: %i[show edit create update] do
diff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rb
index 85cc7906d98..2ab8046ec97 100644
--- a/spec/features/projects/projects_index_spec.rb
+++ b/spec/features/projects/projects_index_spec.rb
@@ -1161,15 +1161,18 @@ RSpec.describe 'Projects index page',
let!(:member) { create(:member, principal: admin, project:, roles: [developer]) }
- it 'allows saving and loading persisted filter sets with them being displayed in the sidebar' do
+ it 'allows saving, loading and deleting persisted filters' do
projects_page.visit!
+ # Adding some filters
projects_page.open_filters
projects_page.filter_by_membership('yes')
+ # The filters are applied
projects_page.expect_projects_listed(project)
projects_page.expect_projects_not_listed(public_project, development_project)
+ # Saving the query will lead to it being displayed in the sidebar
projects_page.save_query('My saved query')
projects_page.expect_sidebar_filter('My saved query', selected: false)
@@ -1186,6 +1189,12 @@ RSpec.describe 'Projects index page',
projects_page.expect_projects_listed(project)
projects_page.expect_projects_not_listed(public_project, development_project)
+
+ # The query can be deleted
+ projects_page.delete_query
+
+ # It will then also be removed from the sidebar
+ projects_page.expect_no_sidebar_filter('My saved query')
end
end
end
diff --git a/spec/routing/project_menu_routing_spec.rb b/spec/routing/project_menu_routing_spec.rb
new file mode 100644
index 00000000000..6930406b3fb
--- /dev/null
+++ b/spec/routing/project_menu_routing_spec.rb
@@ -0,0 +1,35 @@
+# -- 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.
+# ++
+
+require 'spec_helper'
+
+RSpec.describe 'Project menu routes' do
+ it '/projects/menu GET routes to projects/menus#show' do
+ expect(get('/projects/menu')).to route_to('projects/menus#show')
+ end
+end
diff --git a/spec/routing/project_queries_routing_spec.rb b/spec/routing/project_queries_routing_spec.rb
new file mode 100644
index 00000000000..1b55d5eb21f
--- /dev/null
+++ b/spec/routing/project_queries_routing_spec.rb
@@ -0,0 +1,40 @@
+# -- 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.
+# ++
+
+require 'spec_helper'
+
+RSpec.describe 'Project query routes' do
+ it '/projects/queries POST routes to projects/queries#create' do
+ expect(post('/projects/queries')).to route_to('projects/queries#create')
+ end
+
+ it '/projects/queries/:id DELETE routes to projects/queries#destroy' do
+ expect(delete('/projects/queries/42')).to route_to('projects/queries#destroy',
+ id: '42')
+ end
+end
diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rb
index b18235df5c3..4387bd6ab6e 100644
--- a/spec/support/pages/projects/index.rb
+++ b/spec/support/pages/projects/index.rb
@@ -80,6 +80,12 @@ module Pages
end
end
+ def expect_no_sidebar_filter(filter_name)
+ within '#main-menu' do
+ expect(page).to have_no_css(".op-sidemenu--item-action", text: filter_name)
+ end
+ end
+
def set_sidebar_filter(filter_name)
within '#main-menu' do
click_link text: filter_name
@@ -244,6 +250,10 @@ module Pages
end
end
+ def delete_query
+ click_more_menu_item('Delete')
+ end
+
private
def boolean_filter?(filter)