From b6854bc41609fe42bcb5bae733f9ffc4524d3ea6 Mon Sep 17 00:00:00 2001 From: viehlieb Date: Tue, 6 Sep 2022 23:41:19 +0200 Subject: [PATCH] add authentication to group_order_invoices controller --- .../group_order_invoices_controller.rb | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/controllers/group_order_invoices_controller.rb b/app/controllers/group_order_invoices_controller.rb index 7ba9b760..5fcca2d7 100644 --- a/app/controllers/group_order_invoices_controller.rb +++ b/app/controllers/group_order_invoices_controller.rb @@ -1,19 +1,22 @@ class GroupOrderInvoicesController < ApplicationController include Concerns::SendGroupOrderInvoicePdf + before_action :authenticate_finance def show - @group_order_invoice = GroupOrderInvoice.find(params[:id]) - if FoodsoftConfig[:contact][:tax_number] - respond_to do |format| - format.pdf do - send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig[:contact][:tax_number] + begin + @group_order_invoice = GroupOrderInvoice.find(params[:id]) + if FoodsoftConfig[:contact][:tax_number] + respond_to do |format| + format.pdf do + send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig[:contact][:tax_number] + end end + else + raise RecordInvalid end - else - raise RecordInvalid + rescue ActiveRecord::RecordInvalid => error + redirect_back fallback_location: root_path, notice: 'Something went wrong', alert: I18n.t('errors.general_msg', msg: "#{error} " + I18n.t('errors.check_tax_number')) end - rescue => error - redirect_back fallback_location: root_path, notice: 'Something went wrong', alert: I18n.t('errors.general_msg', msg: "#{error} " + I18n.t('errors.check_tax_number')) end def destroy