21
1
Fork 0
mirror of https://github.com/Evolix/chexpire.git synced 2024-05-05 18:25:09 +02:00
chexpire/app/mailers/notifications_mailer.rb
Colin Darie ea610ee185
Notifications grouped of checks in error to user email.
This is not dependent of Notificatioon model.
2018-08-01 23:09:08 +02:00

39 lines
1.2 KiB
Ruby

class NotificationsMailer < ApplicationMailer
helper :application
before_action except: :recurrent_failures do
@notification = params.fetch(:notification)
@check = @notification.check
end
def domain_expires_soon
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
mail subject: subject, to: @notification.recipient
end
end
def ssl_expires_soon
@expire_in_days = Integer(@check.domain_expires_at.to_date - Date.today)
I18n.with_locale params&.fetch(:locale) { @check.user.locale } do
subject = t(".subject", domain: @check.domain, count: @expire_in_days)
mail subject: subject, to: @notification.recipient
end
end
def recurrent_failures(user, checks)
@checks = checks
# params generally not set, except for preview mailer
params_locale = (params[:locale] if params.present?)
I18n.with_locale params_locale || user.locale do
subject = t(".subject", count: checks.count, domain: checks.first.domain)
mail subject: subject, to: user.email
end
end
end