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
[#64885] Impl. Danger Dialog for Project Delete
Alexander Brandon Coles0936b2a717f9
diff --git a/app/components/projects/delete_dialog_component.html.erb b/app/components/projects/delete_dialog_component.html.erbnew file mode 100644index 00000000000..c20e5fce09c--- /dev/null+++ b/app/components/projects/delete_dialog_component.html.erb@@ -0,0 +1,64 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 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.++++#%>++<%=+ render(+ Primer::OpenProject::DangerDialog.new(+ id:,+ title: t(:"project.destroy.title", name: @project),+ form_arguments: {+ action: project_path(@project),+ method: :delete,+ data: { turbo: false }+ }+ )+ ) do |dialog|+ dialog.with_confirmation_message do |message|+ message.with_heading(tag: :h2) { t(:"project.destroy.heading", name: @project) }+ message.with_description do+ t("project.destroy.info")+ end+ end+ dialog.with_confirmation_check_box_content(I18n.t(:text_permanent_delete_confirmation_checkbox_label))+ dialog.with_additional_details(display: :block) do+%>+ <p><%= t("project.destroy.confirmation", identifier: @project.identifier) %></p>+ <ul class="mb-3">+ <li><%= t("project.destroy.project_delete_result_1") %></li>+ <% if has_managed_project_folders? %>+ <li><%= t("project.destroy.project_delete_result_2") %></li>+ <% end %>+ </ul>+ <% if subproject_names.any? %>+ <%= t("project.destroy.subprojects_confirmation", value: subproject_names.to_sentence) %>+ <% end %>+<%+ end+ end+%>diff --git a/app/components/projects/delete_dialog_component.rb b/app/components/projects/delete_dialog_component.rbnew file mode 100644index 00000000000..27c3c0be1d1--- /dev/null+++ b/app/components/projects/delete_dialog_component.rb@@ -0,0 +1,52 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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+ class DeleteDialogComponent < ApplicationComponent+ include ApplicationHelper+ include OpTurbo::Streamable++ def initialize(project:)+ super++ @project = project+ end++ private++ def id = "delete-project-dialog"++ def has_managed_project_folders? = @project.project_storages.any?(&:project_folder_automatic?)++ def subproject_names+ @project.descendants.map(&:to_s)+ end+ end+enddiff --git a/app/components/projects/settings/index_page_header_component.html.erb b/app/components/projects/settings/index_page_header_component.html.erbindex 57ffb6b2482..6f7ad6fdd90 100644--- a/app/components/projects/settings/index_page_header_component.html.erb+++ b/app/components/projects/settings/index_page_header_component.html.erb@@ -109,7 +109,7 @@label: t(:button_delete),href: confirm_destroy_project_path(@project),content_arguments: {- data: { turbo: false },+ data: { turbo_stream: true },test_selector: "project-settings--delete"}) do |item|diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex d57cdb60244..cee00f97784 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -55,8 +55,6 @@ class ProjectsController < ApplicationControllerinclude ProjectsHelperinclude Queries::Loading- helper_method :has_managed_project_folders?-current_menu_item :index do:projectsend@@ -150,8 +148,8 @@ class ProjectsController < ApplicationController# Delete @projectdef destroyservice_call = ::Projects::ScheduleDeletionService- .new(user: current_user, model: @project)- .call+ .new(user: current_user, model: @project)+ .callif service_call.success?flash[:notice] = I18n.t("projects.delete.scheduled")@@ -159,13 +157,11 @@ class ProjectsController < ApplicationControllerflash[:error] = I18n.t("projects.delete.schedule_failed", errors: service_call.errors.full_messages.join("\n"))end- redirect_to projects_path+ redirect_to projects_path, status: :see_otherenddef destroy_info- @project_to_destroy = @project-- hide_project_in_layout+ respond_with_dialog Projects::DeleteDialogComponent.new(project: @project)enddef deactivate_work_package_attachments@@ -248,14 +244,6 @@ class ProjectsController < ApplicationController@parent = Project.visible(current_user).find(params[:parent_id]) if params[:parent_id].present?end- def has_managed_project_folders?(project)- project.project_storages.any?(&:project_folder_automatic?)- end-- def hide_project_in_layout- @project = nil- end-def export_list(query, mime_type)job = Projects::ExportJob.perform_later(export: Projects::Export.create,diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 923315654fc..92f2e013fab 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3892,13 +3892,13 @@ en:one: "1 project"other: "%{count} projects"destroy:- confirmation: "If you continue, the project %{identifier} will be permanently destroyed. To confirm this action please introduce the project name in the field below, this will:"+ confirmation: "If you continue, the project %{identifier} will be permanently destroyed. You will:"project_delete_result_1: "Delete all related data."project_delete_result_2: "Delete all managed project folders in the attached storages."- info: "Deleting the project is an irreversible action."- project_verification: "Enter the project's name %{name} to verify the deletion."+ info: "Deleting the project is an irreversible action. Please proceed with caution."subprojects_confirmation: "Its subproject(s): %{value} will also be deleted."- title: "Delete the project %{name}"+ title: "Delete project %{name}"+ heading: "Permanently delete project %{name}?"filters:project_phase: "Project phase: %{phase}"project_phase_any: "Project phase: Any"diff --git a/spec/components/projects/delete_dialog_component_spec.rb b/spec/components/projects/delete_dialog_component_spec.rbnew file mode 100644index 00000000000..da8dd69774a--- /dev/null+++ b/spec/components/projects/delete_dialog_component_spec.rb@@ -0,0 +1,65 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 "rails_helper"++RSpec.describe Projects::DeleteDialogComponent, type: :component do+ include Rails.application.routes.url_helpers++ let(:project) { build_stubbed(:project, name: "Top Secret Project") }+ let(:user) { build_stubbed(:user) }++ subject do+ render_inline(described_class.new(project:))+ page+ end++ before do+ login_as(user)+ end++ describe "dialog form" do+ let(:project) { build_stubbed(:project) }++ it "renders the correct form action" do+ expect(subject).to have_element "form", action: project_path(project)+ end+ end++ describe "with a project" do+ it "shows a heading" do+ expect(subject).to have_text "Permanently delete project Top Secret Project?"+ end++ it "shows a simple info message" do+ expect(subject).to have_text "Deleting the project is an irreversible action. Please proceed with caution."+ end+ end+enddiff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rbindex 74fa9ac70c5..b2cbfba910b 100644--- a/spec/controllers/projects_controller_spec.rb+++ b/spec/controllers/projects_controller_spec.rb@@ -391,9 +391,9 @@ RSpec.describe ProjectsController dolet(:project) { create(:project, identifier: "blog") }it "gets destroy info" do- get :destroy_info, params: { id: project.id }+ get :destroy_info, params: { id: project.id }, format: :turbo_streamexpect(response).to be_successful- expect(response).to render_template "destroy_info"+ expect(response).to have_turbo_stream action: "dialog", target: "projects-delete-dialog-component"expect { project.reload }.not_to raise_errorenddiff --git a/spec/features/projects/destroy_spec.rb b/spec/features/projects/destroy_spec.rbindex dbc2010505d..b75e56c9462 100644--- a/spec/features/projects/destroy_spec.rb+++ b/spec/features/projects/destroy_spec.rb@@ -32,30 +32,34 @@ require "spec_helper"RSpec.describe "Projects#destroy", :js dolet!(:project) { create(:project, name: "foo", identifier: "foo") }- let(:project_page) { Pages::Projects::Destroy.new(project) }- let(:danger_zone) { DangerZone.new(page) }+ let(:project_page) { Pages::Projects::Settings::General.new(project) }current_user { create(:admin) }- before { project_page.visit! }+ before do+ project_page.visit!+ project_page.click_delete_action+ endit "destroys the project" do- # Confirm the deletion- # Without confirmation, the button is disabled- expect(danger_zone).to be_disabled+ expect(page).to have_modal "Delete project foo"+ within_modal "Delete project foo" do+ expect(page).to have_heading "Permanently delete project foo?"++ expect(page).to have_unchecked_field "I understand that this deletion cannot be reversed"- # With wrong confirmation, the button is disabled- danger_zone.confirm_with("#{project.identifier}_wrong")+ # Without confirmation, the button is disabled+ expect(page).to have_button "Delete permanently", disabled: true- expect(danger_zone).to be_disabled+ # Confirm the deletion+ check "I understand that this deletion cannot be reversed", allow_label_click: true+ expect(page).to have_button "Delete permanently", disabled: false- # With correct confirmation, the button is enabled- # and the project can be deleted- danger_zone.confirm_with(project.identifier)- expect(danger_zone).not_to be_disabled- danger_zone.danger_button.click+ click_on "Delete permanently"+ end+ expect(page).to have_no_modal "Delete project foo"- expect_flash message: I18n.t("projects.delete.scheduled")+ expect_flash type: :success, message: I18n.t("projects.delete.scheduled")expect(project.reload).to eq(project)perform_enqueued_jobsdiff --git a/spec/support/pages/projects/settings/general.rb b/spec/support/pages/projects/settings/general.rbindex ac1064b7813..ed4162015f9 100644--- a/spec/support/pages/projects/settings/general.rb+++ b/spec/support/pages/projects/settings/general.rb@@ -48,7 +48,12 @@ module Pagesdef click_copy_actionpage.find_test_selector("project-settings-more-menu").click- page.find_test_selector("project-settings--copy").click+ page.find(:menuitem, "Copy").click # TODO: scope to More menu+ end++ def click_delete_action+ page.find_test_selector("project-settings-more-menu").click+ page.find(:menuitem, "Delete").click # TODO: scope to More menuenddef expect_field_label_with_help_text(label_text)