5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 13:31:42 +00:00
panel/app/mailers/maintenance_mailer.rb

43 lines
1.1 KiB
Ruby
Raw Normal View History

2020-06-16 16:35:08 +00:00
# frozen_string_literal: true
# Envía correos de mantenimiento
class MaintenanceMailer < ApplicationMailer
# Notifica a les usuaries de tareas de mantenimiento
def notice
I18n.with_locale params[:lang] do
attachments['maintenance.ics'] = ics
mail to: params[:email],
subject: I18n.t('maintenance_mailer.notice.subject')
end
end
# Notifica que volvimos
def were_back
2020-09-11 17:26:19 +00:00
I18n.with_locale params[:lang] do
mail to: params[:email],
subject: I18n.t('maintenance_mailer.were_back.subject')
2020-06-16 16:35:08 +00:00
end
end
private
def cache_key
@cache_key ||= params[:maintenance].cache_key_with_version + '/ics/' + params[:lang]
end
def ics
Rails.cache.fetch(cache_key, expires_in: 1.hour) do
cal = Icalendar::Calendar.new
cal.event do |e|
e.dtstart = params[:maintenance].estimated_from
e.dtend = params[:maintenance].estimated_to
e.summary = I18n.t('maintenance_mailer.ics.summary')
e.description = params[:maintenance].message
end
{ mimetype: 'text/calendar; charset=utf-8', content: cal.to_ical }
end
end
end