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

[#55968] Implement project removal with warning dialog before removing the project

Judith Rothde871872860d
diff --git a/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.html.erb b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.html.erb
new file mode 100644
index 00000000000..68ce6de0125
--- /dev/null
+++ b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.html.erb
@@ -0,0 +1,86 @@
+<%#-- copyright
+OpenProject is an open source project management software.
+Copyright (C) 2012-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.
+
+++#%>
+
+<%=
+ primer_form_with(
+ model: @project_storage,
+ url: admin_settings_storage_project_storage_path(id: @project_storage),
+ data: {
+ turbo: true,
+ controller: 'disable-when-checked',
+ 'disable-when-checked-reversed-value': true
+ },
+ method: :delete
+ ) do |form|
+ render(Primer::Alpha::Dialog.new(
+ id: id,
+ title: nil,
+ test_selector: id,
+ size: :large
+ )) do |dialog|
+ dialog.with_body do
+ flex_layout do |layout|
+ layout.with_row(mb: 3) do
+ render(Primer::Beta::Heading.new(tag: :h1, text_align: :center)) do
+ render(Primer::Beta::Octicon.new(icon: :alert, color: :danger, size: :medium))
+ end
+ end
+ layout.with_row(mb: 1) do
+ render(Primer::Beta::Heading.new(tag: :h2, color: :default, text_align: :center)) do
+ heading
+ end
+ end
+ layout.with_row(mb: 2) do
+ render(Primer::Beta::Text.new(tag: :p, color: :subtle, text_align: :center)) do
+ text
+ end
+ end
+ layout.with_row do
+ render(Primer::Alpha::CheckBox.new(
+ name: "confirm_delete",
+ label: confirmation_text,
+ data: { 'disable-when-checked-target': 'cause' }
+ ))
+ end
+ end
+ end
+ dialog.with_footer do
+ component_collection do |footer|
+ footer.with_component(Primer::ButtonComponent.new(data: { 'close-dialog-id': id })) do
+ I18n.t("button_close")
+ end
+ footer.with_component(Primer::ButtonComponent.new(scheme: :danger, type: :submit, test_selector: "remove-project-storage-button", disabled: true, data: { 'disable-when-checked-target': 'effect' })) do
+ I18n.t("button_remove")
+ end
+ end
+ end
+ end
+ end
+%>
+
diff --git a/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.rb b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.rb
new file mode 100644
index 00000000000..4884cce35d1
--- /dev/null
+++ b/modules/storages/app/components/storages/project_storages/destroy_confirmation_dialog_component.rb
@@ -0,0 +1,64 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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.
+#++
+
+# This components renders a dialog to confirm the deletion of a project from a storage.
+module Storages::ProjectStorages
+ class DestroyConfirmationDialogComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+
+ def initialize(storage:, project_storage:)
+ super
+
+ @storage = storage
+ @project_storage = project_storage
+ end
+
+ def id
+ "project-storage-#{@project_storage.id}-destroy-confirmation-dialog"
+ end
+
+ def heading
+ I18n.t("project_storages.remove_project.dialog.heading",
+ storage_type: I18n.t("storages.provider_types.#{@storage.short_provider_type}.name"))
+ end
+
+ def text
+ text = I18n.t("project_storages.remove_project.dialog.text")
+ if @project_storage.project_folder_mode == "automatic"
+ text << " "
+ text << I18n.t("project_storages.remove_project.dialog.automatically_managed_appendix")
+ end
+ text
+ end
+
+ def confirmation_text
+ I18n.t("project_storages.remove_project.dialog.confirmation_text")
+ end
+ end
+end
diff --git a/modules/storages/app/components/storages/project_storages/projects/row_component.rb b/modules/storages/app/components/storages/project_storages/projects/row_component.rb
index 65b9e737fc4..8e4a4ab7679 100644
--- a/modules/storages/app/components/storages/project_storages/projects/row_component.rb
+++ b/modules/storages/app/components/storages/project_storages/projects/row_component.rb
@@ -30,13 +30,34 @@
# associated with a Storage
module Storages::ProjectStorages::Projects
class RowComponent < Projects::RowComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ include OpTurbo::Streamable
+
def project_folder_type
- project_folder_mode = table.project_folder_modes_per_project[project.id]
+ project_folder_mode = table.project_storages[project.id].project_folder_mode
I18n.t("project_storages.project_folder_mode.#{project_folder_mode}")
end
def more_menu_items
- @more_menu_items ||= []
+ @more_menu_items ||= [more_menu_detach_project].compact
+ end
+
+ private
+
+ def more_menu_detach_project
+ project = model.first
+ if User.current.admin && project.active?
+ {
+ scheme: :danger,
+ icon: :trash,
+ label: I18n.t("project_storages.remove_project.label"),
+ href: destroy_confirmation_dialog_admin_settings_storage_project_storage_path(
+ id: table.project_storages[project.id].id
+ ),
+ data: {
+ controller: "async-dialog"
+ }
+ }
+ end
end
end
end
diff --git a/modules/storages/app/components/storages/project_storages/projects/table_component.rb b/modules/storages/app/components/storages/project_storages/projects/table_component.rb
index 5a14bf6b37b..7fffb53bc76 100644
--- a/modules/storages/app/components/storages/project_storages/projects/table_component.rb
+++ b/modules/storages/app/components/storages/project_storages/projects/table_component.rb
@@ -34,7 +34,7 @@ module Storages::ProjectStorages::Projects
class TableComponent < Projects::TableComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
include OpTurbo::Streamable
- options :project_folder_modes_per_project
+ options :storage
def columns
@columns ||= query
@@ -48,9 +48,18 @@ module Storages::ProjectStorages::Projects
# Overwritten to avoid loading data that is not needed in this context
def projects(query)
- query
+ @projects ||= query
.results
.paginate(page: helpers.page_param(params), per_page: helpers.per_page_param(params))
end
+
+ # Load the project_storages for the current paginated batch of projects grouped
+ # by project_id to fill in other columns
+ def project_storages
+ @project_storages ||= Storages::ProjectStorage
+ .where(storage_id: storage.id)
+ .where(project_id: @projects.map(&:id))
+ .index_by(&:project_id)
+ end
end
end
diff --git a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
index 17dbf108e05..616f4d1eb89 100644
--- a/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/storages/project_storages_controller.rb
@@ -30,6 +30,7 @@
class Storages::Admin::Storages::ProjectStoragesController < ApplicationController
include OpTurbo::ComponentStream
+ include OpTurbo::DialogStreamHelper
layout "admin"
@@ -37,6 +38,7 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
before_action :require_admin
before_action :find_model_object
+ before_action :load_project_storage, only: %i(destroy destroy_confirmation_dialog)
menu_item :external_file_storages
@@ -48,20 +50,29 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControll
query.select(:name)
query.order("lft" => "asc")
end
-
- # Prepare data for project_folder_type column
- @project_folder_modes_per_project = Storages::ProjectStorage
- .where(storage_id: @storage.id)
- .pluck(:project_id, :project_folder_mode)
- .to_h
end
def new; end
def create; end
- def destroy; end
+
+ def destroy_confirmation_dialog
+ respond_with_dialog Storages::ProjectStorages::DestroyConfirmationDialogComponent.new(
+ storage: @storage,
+ project_storage: @project_storage
+ )
+ end
+
+ def destroy
+ @project_storage.destroy
+ redirect_to admin_settings_storage_project_storages_path(@storage)
+ end
private
+ def load_project_storage
+ @project_storage = Storages::ProjectStorage.find(params[:id])
+ end
+
def find_model_object(object_id = :storage_id)
super
@storage = @object
diff --git a/modules/storages/app/views/storages/admin/storages/project_storages/index.html.erb b/modules/storages/app/views/storages/admin/storages/project_storages/index.html.erb
index b0df96649a9..3f2343c2fd3 100644
--- a/modules/storages/app/views/storages/admin/storages/project_storages/index.html.erb
+++ b/modules/storages/app/views/storages/admin/storages/project_storages/index.html.erb
@@ -54,7 +54,7 @@ See COPYRIGHT and LICENSE files for more details.
<%=
render(Storages::ProjectStorages::Projects::TableComponent.new(
query: @project_query,
- project_folder_modes_per_project: @project_folder_modes_per_project,
+ storage: @storage,
params:)
)
%>
diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.yml
index 0c556697ca5..9ccae1b559c 100644
--- a/modules/storages/config/locales/en.yml
+++ b/modules/storages/config/locales/en.yml
@@ -59,6 +59,13 @@ en:
automatic: Automatically managed
inactive: No specific folder
manual: Existing folder manually managed
+ remove_project:
+ dialog:
+ automatically_managed_appendix: Also, in this case this storage has an automatically managed project folder, this and its files will be deleted forever.
+ confirmation_text: Please, confirm you understand and want to remove this file storage from this project
+ heading: Remove project from %{storage_type}
+ text: This action is irreversible and will remove all links from work packages of this project to files and folders of that storage.
+ label: Remove project
storages:
buttons:
complete_without_setup: Complete without it
diff --git a/modules/storages/config/routes.rb b/modules/storages/config/routes.rb
index 963f9eb1482..03d39a0dbf5 100644
--- a/modules/storages/config/routes.rb
+++ b/modules/storages/config/routes.rb
@@ -47,7 +47,9 @@ Rails.application.routes.draw do
scope module: :storages do
resources :project_storages,
controller: "/storages/admin/storages/project_storages",
- only: %i[index new create destroy]
+ only: %i[index new create destroy] do
+ get :destroy_confirmation_dialog, on: :member
+ end
end
resource :connection_validation,
diff --git a/modules/storages/spec/components/storages/project_storages/destroy_confirmation_dialog_component_spec.rb b/modules/storages/spec/components/storages/project_storages/destroy_confirmation_dialog_component_spec.rb
new file mode 100644
index 00000000000..3f6782f6659
--- /dev/null
+++ b/modules/storages/spec/components/storages/project_storages/destroy_confirmation_dialog_component_spec.rb
@@ -0,0 +1,74 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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_relative "../../../spec_helper"
+
+RSpec.describe Storages::ProjectStorages::DestroyConfirmationDialogComponent,
+ type: :component do
+ describe "#heading" do
+ it "contains the storage type" do
+ storage = create(:one_drive_storage)
+ project_storage = build_stubbed(:project_storage, storage:)
+
+ component = described_class.new(storage:, project_storage:)
+ expect(component.heading).to include("OneDrive/SharePoint")
+ expect(component.heading).not_to include("Nextcloud")
+ end
+ end
+
+ describe "#text" do
+ let(:storage) { create(:storage, :as_generic) }
+
+ context "for a project with automatically managed project folder" do
+ it "includes an additional hint for data loss" do
+ project_storage = build_stubbed(:project_storage, storage:, project_folder_mode: "automatic")
+ component = described_class.new(storage:, project_storage:)
+ expect(component.text).to include("irreversible")
+ expect(component.text).to include("files will be deleted forever")
+ end
+ end
+
+ context "for a project with manual managed folder" do
+ it "includes only the basic hint" do
+ project_storage = build_stubbed(:project_storage, storage:, project_folder_mode: "manual")
+ component = described_class.new(storage:, project_storage:)
+ expect(component.text).to include("irreversible")
+ expect(component.text).not_to include("files will be deleted forever")
+ end
+ end
+
+ context "for a project with unmanaged folder" do
+ it "includes only the basic hint" do
+ project_storage = build_stubbed(:project_storage, storage:, project_folder_mode: "inactive")
+ component = described_class.new(storage:, project_storage:)
+ expect(component.text).to include("irreversible")
+ expect(component.text).not_to include("files will be deleted forever")
+ end
+ end
+ end
+end
diff --git a/modules/storages/spec/components/project_storages/row_component_spec.rb b/modules/storages/spec/components/storages/project_storages/row_component_spec.rb
similarity index 98%
rename from modules/storages/spec/components/project_storages/row_component_spec.rb
rename to modules/storages/spec/components/storages/project_storages/row_component_spec.rb
index 94d176a06c2..01720fd73a6 100644
--- a/modules/storages/spec/components/project_storages/row_component_spec.rb
+++ b/modules/storages/spec/components/storages/project_storages/row_component_spec.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
#
-require_relative "../../spec_helper"
+require_relative "../../../spec_helper"
RSpec.describe Storages::ProjectStorages::RowComponent,
type: :component do
diff --git a/modules/storages/spec/features/storages/admin/project_storages_spec.rb b/modules/storages/spec/features/storages/admin/project_storages_spec.rb
index 7e621e9ce3b..03a5b95b842 100644
--- a/modules/storages/spec/features/storages/admin/project_storages_spec.rb
+++ b/modules/storages/spec/features/storages/admin/project_storages_spec.rb
@@ -62,6 +62,8 @@ RSpec.describe "Admin lists project mappings for a storage",
project_folder_mode: "inactive")
end
+ let(:project_storages_index_page) { Pages::Admin::Storages::ProjectStorages::Index.new }
+
current_user { admin }
context "with insufficient permissions" do
@@ -111,5 +113,33 @@ RSpec.describe "Admin lists project mappings for a storage",
end
end
end
+
+ describe "Removal of a project from a storage" do
+ it "shows a warning dialog that can be aborted" do
+ expect(page).to have_text(project.name)
+ project_storages_index_page.click_menu_item_of("Remove project", project)
+
+ page.within("dialog") do
+ expect(page).to have_text("Remove project from Nextcloud")
+ expect(page).to have_text("this storage has an automatically managed project folder")
+ click_on "Close"
+ end
+
+ expect(page).to have_text(project.name)
+ end
+
+ it "is possible to remove the project after checking the confirmation checkbox in the dialog" do
+ expect(page).to have_text(project.name)
+ project_storages_index_page.click_menu_item_of("Remove project", project)
+
+ page.within("dialog") do
+ expect(page).to have_button("Remove", disabled: true)
+ check "Please, confirm you understand and want to remove this file storage from this project"
+ click_on "Remove"
+ end
+
+ expect(page).to have_no_text(project.name)
+ end
+ end
end
end
diff --git a/modules/storages/spec/support/pages/admin/storages/project_storages/project_storages_index.rb b/modules/storages/spec/support/pages/admin/storages/project_storages/project_storages_index.rb
new file mode 100644
index 00000000000..754cdb63b2e
--- /dev/null
+++ b/modules/storages/spec/support/pages/admin/storages/project_storages/project_storages_index.rb
@@ -0,0 +1,43 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-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 "support/pages/projects/index"
+
+module Pages
+ module Admin
+ module Storages
+ module ProjectStorages
+ class Index < ::Pages::Projects::Index
+ def path
+ "/admin/settings/storages/#{storage.id}/project_storages"
+ end
+ end
+ end
+ end
+ end
+end