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
query deletion
ulfertse758a2b51dd3
diff --git a/app/components/projects/index_page_header_component.html.erb b/app/components/projects/index_page_header_component.html.erbindex 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+ endend%><% end %>diff --git a/app/controllers/projects/menus_controller.rb b/app/controllers/projects/menus_controller.rbindex 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)]enddiff --git a/app/controllers/projects/queries_controller.rb b/app/controllers/projects/queries_controller.rbindex 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 authorizationdef createquery = load_query@@ -37,9 +39,20 @@ class Projects::QueriesController < ApplicationControllerredirect_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_controllerdef load_query@query = ParamsToQueryService.new(Project, current_user).call(params)end++ def find_query+ @query = Queries::Projects::ProjectQuery.find(params[:id])+ endenddiff --git a/config/routes.rb b/config/routes.rbindex 07d061f8854..6973ac6dec1 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -181,7 +181,7 @@ OpenProject::Application.routes.draw donamespace :projects doresource :menu, only: %i[show]- resources :queries, only: %i[create]+ resources :queries, only: %i[create destroy]endresources :projects, except: %i[show edit create update] dodiff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rbindex 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' doprojects_page.visit!+ # Adding some filtersprojects_page.open_filtersprojects_page.filter_by_membership('yes')+ # The filters are appliedprojects_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 sidebarprojects_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')endendenddiff --git a/spec/routing/project_menu_routing_spec.rb b/spec/routing/project_menu_routing_spec.rbnew file mode 100644index 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+enddiff --git a/spec/routing/project_queries_routing_spec.rb b/spec/routing/project_queries_routing_spec.rbnew file mode 100644index 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+enddiff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rbindex b18235df5c3..4387bd6ab6e 100644--- a/spec/support/pages/projects/index.rb+++ b/spec/support/pages/projects/index.rb@@ -80,6 +80,12 @@ module Pagesendend+ 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' doclick_link text: filter_name@@ -244,6 +250,10 @@ module Pagesendend+ def delete_query+ click_more_menu_item('Delete')+ end+privatedef boolean_filter?(filter)