Skip to content

Commit

Permalink
fix[Op#50985]: Update delete storage flash messages to primer
Browse files Browse the repository at this point in the history
  • Loading branch information
akabiru committed Nov 30, 2023
1 parent 0f5ea25 commit 88c23a9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 }
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions modules/storages/spec/features/admin_storages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 88c23a9

Please sign in to comment.