[Fix #196] Attestation: join the attestation to the closed mail

Add a upper limit to the attachment size as it could be a problem with Mailjet and receiver
(https://www.mailjet.com/support/what-is-the-size-limit-for-attachments-files-sent-via-mailjet,289.htm)

If the attestation cannot be sent, it is logged in sentry
This commit is contained in:
Simon Lehericey 2017-06-09 22:29:48 +02:00
parent b664709c3d
commit e60ce35ae8
7 changed files with 114 additions and 18 deletions

View file

@ -1,4 +1,6 @@
class Backoffice::DossiersController < Backoffice::DossiersListController
include ActionView::Helpers::NumberHelper
respond_to :html, :xlsx, :ods, :csv
prepend_before_action :store_current_location, only: :show
@ -112,6 +114,8 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
dossier = @facade.dossier
attestation_pdf = nil
case params[:process_action]
when "refuse"
next_step = "refuse"
@ -125,12 +129,15 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
next_step = "close"
notice = "Dossier traité avec succès."
template = dossier.procedure.closed_mail_template
if check_attestation_emailable(dossier)
attestation_pdf = dossier.attestation.pdf.read
end
end
dossier.next_step! 'gestionnaire', next_step, motivation
flash.notice = notice
NotificationMailer.send_notification(dossier, template).deliver_now!
NotificationMailer.send_notification(dossier, template, attestation_pdf).deliver_now!
redirect_to backoffice_dossier_path(id: dossier.id)
end
@ -185,6 +192,16 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
private
def check_attestation_emailable(dossier)
if dossier&.attestation&.emailable? == false
human_size = number_to_human_size(dossier.attestation.pdf.size)
msg = "the attestation of the dossier #{dossier.id} cannot be mailed because it is too heavy: #{human_size}"
capture_message(msg, level: 'error')
end
dossier&.attestation&.emailable?
end
def store_current_location
if !gestionnaire_signed_in?
store_location_for(:gestionnaire, request.url)