diff --git a/modules/storages/app/controllers/storages/admin/storages_controller.rb b/modules/storages/app/controllers/storages/admin/storages_controller.rb index 6ad24737f62c..3bf99d2784ea 100644 --- a/modules/storages/app/controllers/storages/admin/storages_controller.rb +++ b/modules/storages/app/controllers/storages/admin/storages_controller.rb @@ -31,6 +31,7 @@ # Purpose: CRUD the global admin page of Storages (=Nextcloud servers) class Storages::Admin::StoragesController < ApplicationController using Storages::Peripherals::ServiceResultRefinements + include FlashMessagesHelper # See https://guides.rubyonrails.org/layouts_and_rendering.html for reference on layout layout 'admin' @@ -133,19 +134,14 @@ def edit_host # Update is similar to create above # See also: create above # Called by: Global app/config/routes.rb to serve Web page - def update # rubocop:disable Metrics/AbcSize + def update service_result = ::Storages::Storages::UpdateService .new(user: current_user, model: @storage) .call(permitted_storage_params) @storage = service_result.result if service_result.success? - flash[:notice] = I18n.t(:notice_successful_update) - - respond_to do |format| - format.html { redirect_to edit_admin_settings_storage_path(@storage) } - format.turbo_stream - end + respond_to { |format| format.turbo_stream } else respond_to do |format| format.html { render :edit } @@ -159,15 +155,19 @@ def confirm_destroy end def destroy - Storages::Storages::DeleteService + service_result = Storages::Storages::DeleteService .new(user: User.current, model: @storage) .call - .match( - # rubocop:disable Rails/ActionControllerFlashBeforeRender - on_success: ->(*) { flash[:notice] = I18n.t(:notice_successful_delete) }, - on_failure: ->(error) { flash[:error] = error.full_messages } - # rubocop:enable Rails/ActionControllerFlashBeforeRender - ) + + # rubocop:disable Rails/ActionControllerFlashBeforeRender + service_result.on_failure do + flash[:primer_banner] = { message: join_flash_messages(service_result.errors.full_messages), scheme: :danger } + end + + service_result.on_success do + flash[:primer_banner] = { message: I18n.t(:notice_successful_delete), scheme: :success } + end + # rubocop:enable Rails/ActionControllerFlashBeforeRender redirect_to admin_settings_storages_path end diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb index eab0f310d3dd..c470062d5571 100644 --- a/modules/storages/spec/features/admin_storages_spec.rb +++ b/modules/storages/spec/features/admin_storages_spec.rb @@ -373,6 +373,7 @@ storage_delete_button.click expect(page).not_to have_text("Foo Nextcloud") + expect(page).to have_text('Successful deletion.') expect(page).to have_current_path(admin_settings_storages_path) end