2019-10-02 14:37:47 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Handle most of the emails sent by the platform. Triggered by notifications
|
2015-05-05 03:10:25 +02:00
|
|
|
class NotificationsMailer < NotifyWith::NotificationsMailer
|
2019-10-02 14:37:47 +02:00
|
|
|
default from: ENV['DEFAULT_MAIL_FROM']
|
2015-05-05 03:10:25 +02:00
|
|
|
layout 'notifications_mailer'
|
|
|
|
|
|
|
|
helper :application
|
|
|
|
|
2016-03-23 18:39:41 +01:00
|
|
|
def send_mail_by(notification)
|
|
|
|
@notification = notification
|
|
|
|
@recipient = notification.receiver
|
|
|
|
@attached_object = notification.attached_object
|
|
|
|
|
2019-10-02 14:37:47 +02:00
|
|
|
unless respond_to?(notification.notification_type)
|
|
|
|
class_eval %{
|
2016-03-23 18:39:41 +01:00
|
|
|
def #{notification.notification_type}
|
|
|
|
mail to: @recipient.email,
|
|
|
|
subject: t('notifications_mailer.#{notification.notification_type}.subject'),
|
|
|
|
template_name: '#{notification.notification_type}',
|
|
|
|
content_type: 'text/html'
|
|
|
|
end
|
2019-10-02 14:37:47 +02:00
|
|
|
}, __FILE__, __LINE__ - 7
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
send(notification.notification_type)
|
|
|
|
end
|
|
|
|
|
2015-05-05 03:10:25 +02:00
|
|
|
def helpers
|
|
|
|
ActionController::Base.helpers
|
|
|
|
end
|
2016-03-23 18:39:41 +01:00
|
|
|
|
|
|
|
def notify_user_when_invoice_ready
|
2016-03-29 18:02:40 +02:00
|
|
|
attachments[@attached_object.filename] = File.read(@attached_object.file)
|
2019-10-02 14:37:47 +02:00
|
|
|
mail(to: @recipient.email,
|
|
|
|
subject: t('notifications_mailer.notify_member_invoice_ready.subject'),
|
|
|
|
template_name: 'notify_member_invoice_ready')
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def notify_user_when_avoir_ready
|
2016-03-29 18:02:40 +02:00
|
|
|
attachments[@attached_object.filename] = File.read(@attached_object.file)
|
2019-10-02 14:37:47 +02:00
|
|
|
mail(to: @recipient.email,
|
|
|
|
subject: t('notifications_mailer.notify_member_avoir_ready.subject'),
|
|
|
|
template_name: 'notify_member_avoir_ready')
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|