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
[#57038] Trigger the Storages::ProjectStorages::DeleteService when a project is removed from a storage
Judith Rothfa29c3f7bdb1
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.rbindex d26ee25890f..ffe01034793 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@@ -109,10 +109,21 @@ class Storages::Admin::Storages::ProjectStoragesController < ApplicationControllenddef destroy- Storages::ProjectStorages::DeleteService+ result = Storages::ProjectStorages::DeleteService.new(user: current_user, model: @project_storage).call+ # rubocop:disable Rails/ActionControllerFlashBeforeRender+ result.on_success do+ flash[:primer_banner] = { message: I18n.t(:notice_successful_delete) }+ end++ result.on_failure do |failure|+ error = failure.errors.map(&:message).join("; ")+ flash[:primer_banner] = { message: t("project_storages.remove_project.deletion_failure_flash", error:), scheme: :danger }+ end+ # rubocop:enable Rails/ActionControllerFlashBeforeRender+redirect_to admin_settings_storage_project_storages_path(@storage)enddiff --git a/modules/storages/config/locales/en.yml b/modules/storages/config/locales/en.ymlindex 85c7f39b788..337a5fc2edc 100644--- a/modules/storages/config/locales/en.yml+++ b/modules/storages/config/locales/en.yml@@ -73,6 +73,7 @@ en: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+ deletion_failure_flash: "Failed to remove the project from the storage: "services:attributes:nextcloud_sync_service:diff --git a/modules/storages/spec/features/storages/admin/project_storages_spec.rb b/modules/storages/spec/features/storages/admin/project_storages_spec.rbindex e1e4d8a6c83..a0a54aae83b 100644--- a/modules/storages/spec/features/storages/admin/project_storages_spec.rb+++ b/modules/storages/spec/features/storages/admin/project_storages_spec.rb@@ -320,6 +320,20 @@ RSpec.describe "Admin lists project mappings for a storage",enddescribe "Removal of a project from a storage" do+ let(:success_delete_service) do+ Class.new do+ def initialize(user:, model:)+ @user = user+ @model = model+ end++ def call+ @model.destroy!+ ServiceResult.success+ end+ end+ end+it "shows a warning dialog that can be aborted" doexpect(page).to have_text(project.name)project_storages_index_page.click_menu_item_of("Remove project", project)@@ -337,13 +351,23 @@ RSpec.describe "Admin lists project mappings for a storage",expect(page).to have_text(project.name)project_storages_index_page.click_menu_item_of("Remove project", project)+ # The original DeleteService would try to remove actual files from actual storages,+ # which is of course not possible in this test since no real storage is used.+ expect(Storages::ProjectStorages::DeleteService)+ .to receive(:new) # rubocop:disable RSpec/MessageSpies+ .and_wrap_original do |_original_method, *args, &_block|+ user, model = *args.first.values+ success_delete_service.new(user:, model:)+ end+page.within("dialog") doexpect(page).to have_button("Remove", disabled: true)check "Please, confirm you understand and want to remove this file storage from this project"- expect(page).to have_button("Remove", disabled: false, wait: 3) # ensure button is clickable+ wait_for(page).to have_button("Remove", disabled: false) # ensure button is clickableclick_on "Remove"end+ expect(page).to have_text(I18n.t(:notice_successful_delete))expect(page).to have_no_text(project.name)endend