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
[OP#48413] Danger zone when deactivating a storage on a project (#13222)
Kabiru Mwenjaeb4a227597c7
diff --git a/modules/storages/app/components/storages/projects_storages/row_component.rb b/modules/storages/app/components/storages/projects_storages/row_component.rbindex f53d2542b7d..1d184bd5ca4 100644--- a/modules/storages/app/components/storages/projects_storages/row_component.rb+++ b/modules/storages/app/components/storages/projects_storages/row_component.rb@@ -64,11 +64,10 @@ module Storages::ProjectsStoragesdef delete_linklink_to '',- project_settings_projects_storage_path(project_id: project_storage.project, id: project_storage),+ confirm_destroy_project_settings_projects_storage_path(project_id: project_storage.project, id: project_storage),class: 'icon icon-delete',- data: { confirm: I18n.t('storages.delete_warning.project_storage') },title: I18n.t(:button_delete),- method: :delete+ method: :getendendenddiff --git a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rbindex 3503e3715b0..97f35a72c2b 100644--- a/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb+++ b/modules/storages/app/controllers/storages/admin/projects_storages_controller.rb@@ -39,7 +39,7 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsController# This defines @object as the model instance.model_object Storages::ProjectStorage- before_action :find_model_object, only: %i[edit update destroy] # Fill @object with ProjectStorage+ before_action :find_model_object, only: %i[edit update destroy destroy_info] # Fill @object with ProjectStorage# No need to before_action :find_project_by_project_id as SettingsController already checks# No need to check for before_action :authorize, as the SettingsController already checks this.@@ -146,6 +146,12 @@ class Storages::Admin::ProjectsStoragesController < Projects::SettingsControllerredirect_to project_settings_projects_storages_pathend+ def destroy_info+ @project_storage_to_destroy = @object++ render '/storages/project_settings/destroy_info'+ end+private# Define the list of permitted parameters for creating/updating a ProjectStorage.diff --git a/modules/storages/app/views/storages/project_settings/destroy_info.html.erb b/modules/storages/app/views/storages/project_settings/destroy_info.html.erbnew file mode 100644index 00000000000..5fe34316a0a--- /dev/null+++ b/modules/storages/app/views/storages/project_settings/destroy_info.html.erb@@ -0,0 +1,63 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 2012-2023 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.++++#%>+<%= styled_form_tag(project_settings_projects_storage_path(project_id: @project_storage_to_destroy.project, id: @project_storage_to_destroy),+ class: 'danger-zone',+ method: :delete) do %>+ <section class="form--section">+ <h3 class="form--section-title">+ <%= t('storages.page_titles.project_settings.delete') %>+ </h3>+ <p>+ <%= t('storages.delete_warning.project_storage', file_storage: "<strong>#{h(@project_storage_to_destroy.storage.name)}</strong>").html_safe %>+ </p>+ <ul>+ <li> <%= t('storages.delete_warning.project_storage_delete_result_1') %>+ <li> <%= t('storages.delete_warning.project_storage_delete_result_2') %>+ </ul>+ <p class="danger-zone--warning">+ <span class="icon icon-error"></span>+ <span><%= t('storages.delete_warning.irreversible_notice')%></span>+ </p>+ <p>+ <%= t('storages.delete_warning.input_delete_confirmation', file_storage: "<em class=\"danger-zone--expected-value\">#{h(@project_storage_to_destroy.storage.name)}</em>").html_safe %>+ </p>+ <div class="danger-zone--verification">+ <%= text_field_tag :delete_confirmation %>+ <%= styled_button_tag title: t(:button_delete), class: '-highlight', disabled: true do+ concat content_tag :i, '', class: 'button--icon icon-delete'+ concat content_tag :span, t(:button_delete), class: 'button--text'+ end %>+ <%= link_to project_settings_projects_storages_path(@project_storage_to_destroy.project),+ title: t(:button_cancel),+ class: 'button -with-icon icon-cancel' do %>+ <%= t(:button_cancel) %>+ <% end %>+ </div>+ </section>+<% end %>diff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 57fde3fc3ea..101b329f0e1 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -71,6 +71,7 @@ en:index: "File storages available in this project"new: "Add a file storage to this project"edit: "Edit the file storage to this project"+ delete: "Delete file storage"instructions:type: "Please make sure you have administration privileges in your Nextcloud instance and have the following application installed before doing the setup:"type_link_text: "“Integration OpenProject”"@@ -103,8 +104,12 @@ en:Are you sure you want to delete this storage? This will also delete the storage from all projects where it is used.Further, it will also delete all links from work packages to files that are stored in that storage.project_storage: >- Are you sure you want to remove this file storage from this project? This will also- remove all links to files stored in this storage for this project.+ Are you sure you want to delete %{file_storage} from this project? To confirm this action please+ introduce the storage name in the field below, this will:+ project_storage_delete_result_1: "Remove all links from work packages of this project to files and folders of that storage."+ project_storage_delete_result_2: "In case this storage has an automatically managed project folder, this and its files will be deleted forever."+ input_delete_confirmation: "Enter the file storage name %{file_storage} to confirm deletion."+ irreversible_notice: "Deleting a file storage is an irreversible action."label_active: "Active"label_inactive: "Inactive"label_creator: "Creator"diff --git a/modules/storages/config/routes.rb b/modules/storages/config/routes.rbindex 55ed46f795d..d8215473550 100644--- a/modules/storages/config/routes.rb+++ b/modules/storages/config/routes.rb@@ -43,7 +43,12 @@ OpenProject::Application.routes.draw doscope 'projects/:project_id', as: 'project' donamespace 'settings' do- resources :projects_storages, controller: '/storages/admin/projects_storages', except: %i[show]+ resources :projects_storages, controller: '/storages/admin/projects_storages', except: %i[show] do+ member do+ # Destroy uses a get request to prompt the user before the actual DELETE request+ get :destroy_info, as: 'confirm_destroy'+ end+ endendendenddiff --git a/modules/storages/lib/open_project/storages/engine.rb b/modules/storages/lib/open_project/storages/engine.rbindex 5b8735cc3b0..bdb6bbfbdeb 100644--- a/modules/storages/lib/open_project/storages/engine.rb+++ b/modules/storages/lib/open_project/storages/engine.rb@@ -87,7 +87,7 @@ module OpenProject::Storagesdependencies: %i[view_file_links],contract_actions: { file_links: %i[manage] }permission :manage_storages_in_project,- { 'storages/admin/projects_storages': %i[index new edit update create destroy set_permissions] },+ { 'storages/admin/projects_storages': %i[index new edit update create destroy destroy_info set_permissions] },dependencies: %i[]# explicit check for test env is needed, because `with_flag: { managed_project_folders: true }` set for a test casediff --git a/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rb b/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rbindex f0f631ec8db..034a4d6cef8 100644--- a/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rb+++ b/modules/storages/spec/features/delete_project_storage_and_file_links_spec.rb@@ -66,9 +66,21 @@ RSpec.describe 'Delete ProjectStorage with FileLinks', js: true do# Press Delete icon to remove the storage from the projectpage.find('.icon.icon-delete').click- alert_text = page.driver.browser.switch_to.alert.text- expect(alert_text).to have_text 'Are you sure'- page.driver.browser.switch_to.alert.accept++ # Danger zone confirmation flow+ expect(page).to have_selector('.form--section-title', text: "DELETE FILE STORAGE")+ expect(page).to have_selector('.danger-zone--warning', text: "Deleting a file storage is an irreversible action.")+ expect(page).to have_button('Delete', disabled: true)++ # Cancel Confirmation+ page.click_link('Cancel')+ expect(page).to have_current_path project_settings_projects_storages_path(project)++ page.find('.icon.icon-delete').click++ # Approve Confirmation+ page.fill_in 'delete_confirmation', with: storage.name+ page.click_button('Delete')# List of ProjectStorages empty againexpect(page).to have_current_path project_settings_projects_storages_path(project)diff --git a/modules/storages/spec/features/manage_project_storage_spec.rb b/modules/storages/spec/features/manage_project_storage_spec.rbindex fb0a0d1e73f..b47d3b50bff 100644--- a/modules/storages/spec/features/manage_project_storage_spec.rb+++ b/modules/storages/spec/features/manage_project_storage_spec.rb@@ -173,9 +173,21 @@ RSpec.describe(# Press Delete icon to remove the storage from the projectpage.find('.icon.icon-delete').click- alert_text = page.driver.browser.switch_to.alert.text- expect(alert_text).to have_text 'Are you sure'- page.driver.browser.switch_to.alert.accept++ # Danger zone confirmation flow+ expect(page).to have_selector('.form--section-title', text: "DELETE FILE STORAGE")+ expect(page).to have_selector('.danger-zone--warning', text: "Deleting a file storage is an irreversible action.")+ expect(page).to have_button('Delete', disabled: true)++ # Cancel Confirmation+ page.click_link('Cancel')+ expect(page).to have_current_path project_settings_projects_storages_path(project)++ page.find('.icon.icon-delete').click++ # Approve Confirmation+ page.fill_in 'delete_confirmation', with: "Storage 1"+ page.click_button('Delete')# List of ProjectStorages empty againexpect(page).to have_current_path project_settings_projects_storages_path(project)