diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index b4047a41be08c97cdd3f8b13891dfea26206ef5e..a0ee2202114e76c07cbdd9fc52d6643cf67ae6eb 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -129,7 +129,7 @@ class AccountsController < ApplicationController end def redirect_to_new(error_message) - flash[:error] = error_message + flash_error error_message session[:account_email] = params[:account][:email] redirect_to new_account_path false diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c671e378347d4424bcd87844049ce6ebd42ce16b..8f19918c512ed5a6edc053dd80e498f2957d0c5a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -126,7 +126,32 @@ class ApplicationController < ActionController::Base def put_api_messages_as_flash_error if messages = Base.connection.http_response.headers[:x_messages] - flash[:error] = messages + Array(messages).each do |message| + message.split(' // ').each do |msg| + flash_error(msg) + end + end + end + end + + def flash_error(msg) + ensure_flash_is_array('error') + flash['error'] << msg + end + + def flash_notice(msg) + ensure_flash_is_array('notice') + flash['notice'] << msg + end + + private + + def ensure_flash_is_array(name) + case flash[name] + when nil + flash[name] = [] + when String + flash[name] = [flash[name]] end end end diff --git a/app/controllers/keys_controller.rb b/app/controllers/keys_controller.rb index 3595356b1d81503acfc9ab3c62487a82bb34a539..a825fbccc9348524cf2632690cb3aae789572e7f 100644 --- a/app/controllers/keys_controller.rb +++ b/app/controllers/keys_controller.rb @@ -29,26 +29,30 @@ class KeysController < ApplicationController def create input = select_key_material if input.blank? - flash[:alert] = 'No input found' + flash_error 'No input found' return redirect_to action: 'index' end logger.info "input: #{input.inspect}" # ActiveResource doesn't want to use query-params with create(), so here # list_id is included in the request-body. - import_result = Key.create(keymaterial: input, list_id: @list.id) - # TODO: Maybe move the interpretation of the import-result into the - # API-daemon? schleuder-cli is doing the same interpretation, too. - if import_result.considered == 0 + result = Key.create(keymaterial: input, list_id: @list.id) + keys = result.keys + if keys.size == 0 # Can't use :error as argument to redirect_to() - flash[:error] = 'No keys found in input' + flash_error 'No keys found in input' redirect_to list_key_new_path(@list) - else - msg = import_result.imports.map do |import_status| - [import_status.fpr, import_status.action].join(': ') - end.join(', ') - redirect_to list_keys_path(@list), notice: msg + return + end + + keys.each do |key| + if key.import_action == 'error' + flash_error "Unexpected error while importing key #{key.fingerprint}" + else + flash_notice "#{key.import_action.capitalize}: #{key.summary}" + end end + redirect_to list_keys_path(@list) end def destroy diff --git a/app/controllers/subscriptions_controller.rb b/app/controllers/subscriptions_controller.rb index 06f429334a0aa3adaa6b76a08d496c8bfb6813fe..f0d4b8dfc3523d0162d2ef7a35a950000d114e17 100644 --- a/app/controllers/subscriptions_controller.rb +++ b/app/controllers/subscriptions_controller.rb @@ -60,7 +60,7 @@ class SubscriptionsController < ApplicationController def destroy if @subscription.is_last_admin? - flash[:error] = t(".cant_unsubscribe_last_admin") + flash_error t(".cant_unsubscribe_last_admin") redirect_to subscription_path(@subscription) return end