2019-10-02 14:37:47 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Handle most of the emails sent by the platform. Triggered by notifications
|
2023-01-27 13:53:23 +01:00
|
|
|
class NotificationsMailer < BaseMailer
|
|
|
|
after_action :mark_notification_as_send
|
2015-05-05 03:10:25 +02:00
|
|
|
|
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)
|
2023-01-27 13:53:23 +01:00
|
|
|
class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
|
|
|
|
def #{notification.notification_type} # def notify_admin_when_project_published
|
|
|
|
mail to: @recipient.email, # mail to: @recipient.email,
|
|
|
|
subject: t('notifications_mailer.#{notification.notification_type}.subject'), # subject: t('notifications_mailer.notify_admin_when_project_published.subject'),
|
|
|
|
template_name: '#{notification.notification_type}', # template_name: 'notify_admin_when_project_published',
|
|
|
|
content_type: 'text/html' # content_type: 'text/html'
|
|
|
|
end # end
|
|
|
|
RUBY
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
send(notification.notification_type)
|
2021-10-21 15:07:18 +02:00
|
|
|
rescue StandardError => e
|
2022-07-26 17:27:33 +02:00
|
|
|
Rails.logger.error "[NotificationsMailer] notification cannot be sent: #{e}"
|
2016-03-23 18:39:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
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
|
2021-01-19 16:47:51 +01:00
|
|
|
|
|
|
|
def notify_user_when_payment_schedule_ready
|
|
|
|
attachments[@attached_object.filename] = File.read(@attached_object.file)
|
|
|
|
mail(to: @recipient.email,
|
|
|
|
subject: t('notifications_mailer.notify_member_payment_schedule_ready.subject'),
|
|
|
|
template_name: 'notify_member_payment_schedule_ready')
|
|
|
|
end
|
2022-05-10 16:48:58 +02:00
|
|
|
|
|
|
|
def notify_member_create_reservation
|
2022-07-27 12:04:17 +02:00
|
|
|
attachments[@attached_object.ics_filename] = @attached_object.to_ics.encode(Encoding::UTF_8)
|
2022-05-10 16:48:58 +02:00
|
|
|
mail(to: @recipient.email,
|
|
|
|
subject: t('notifications_mailer.notify_member_create_reservation.subject'),
|
|
|
|
template_name: 'notify_member_create_reservation')
|
|
|
|
end
|
2023-01-27 13:53:23 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def mark_notification_as_send
|
|
|
|
@notification.mark_as_send unless @notification.is_send
|
|
|
|
end
|
2015-05-05 03:10:25 +02:00
|
|
|
end
|