2019-07-26 00:36:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Notifica a les usuaries cuando un sitio se generó con éxito
|
|
|
|
#
|
|
|
|
# XXX: No será mejor enviarles un correo con copia?
|
|
|
|
# TODO: Agregar headers de desuscripción de notificaciones cuando
|
|
|
|
# tengamos opciones de usuarie
|
|
|
|
# TODO: Agregar firma GPG y header Autocrypt
|
|
|
|
# TODO: Cifrar con GPG si le usuarie nos dio su llave
|
|
|
|
class DeployMailer < ApplicationMailer
|
2023-02-08 21:55:05 +00:00
|
|
|
include ActionView::Helpers::NumberHelper
|
|
|
|
include ActionView::Helpers::DateHelper
|
|
|
|
|
2019-07-26 00:36:33 +00:00
|
|
|
# rubocop:disable Metrics/AbcSize
|
2023-02-08 21:55:05 +00:00
|
|
|
def deployed(deploys)
|
|
|
|
usuarie = Usuarie.find(params[:usuarie])
|
|
|
|
site = usuarie.sites.find(params[:site])
|
|
|
|
hostname = site.hostname
|
|
|
|
|
2023-03-14 19:45:39 +00:00
|
|
|
# Informamos a cada quien en su idioma y damos una dirección de
|
|
|
|
# respuesta porque a veces les usuaries nos escriben
|
|
|
|
I18n.with_locale(usuarie.lang) do
|
2023-03-14 22:23:17 +00:00
|
|
|
subject = t('.subject', site: site.name)
|
|
|
|
|
2023-03-14 19:45:39 +00:00
|
|
|
@hi = t('.hi')
|
|
|
|
@explanation = t('.explanation', fqdn: hostname)
|
|
|
|
@help = t('.help')
|
2023-02-08 21:55:05 +00:00
|
|
|
|
2023-03-14 19:45:39 +00:00
|
|
|
@headers = %w[type status url seconds size].map do |header|
|
|
|
|
t(".th.#{header}")
|
|
|
|
end
|
2023-02-08 21:55:05 +00:00
|
|
|
|
2023-03-14 19:45:39 +00:00
|
|
|
@table = deploys.each_pair.map do |deploy, value|
|
|
|
|
{
|
|
|
|
title: t(".#{deploy}.title"),
|
|
|
|
status: t(".#{deploy}.#{value[:status] ? 'success' : 'error'}"),
|
|
|
|
urls: value[:urls],
|
|
|
|
seconds: {
|
|
|
|
human: distance_of_time_in_words(value[:seconds].seconds),
|
|
|
|
machine: "PT#{value[:seconds]}S"
|
|
|
|
},
|
|
|
|
size: number_to_human_size(value[:size], precision: 2)
|
|
|
|
}
|
|
|
|
end
|
2023-02-08 21:55:05 +00:00
|
|
|
|
2023-03-14 19:45:39 +00:00
|
|
|
@terminal_table = Terminal::Table.new do |t|
|
|
|
|
t << @headers
|
|
|
|
t.add_separator
|
|
|
|
@table.each do |row|
|
|
|
|
row[:urls].each do |url|
|
|
|
|
t << (row.map do |k, v|
|
|
|
|
case k
|
|
|
|
when :seconds then v[:human]
|
|
|
|
when :urls then url
|
|
|
|
else v
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|
2023-02-08 21:55:05 +00:00
|
|
|
end
|
|
|
|
end
|
2019-07-26 00:36:33 +00:00
|
|
|
|
2023-02-08 21:55:05 +00:00
|
|
|
mail(to: usuarie.email, reply_to: "sutty@#{Site.domain}", subject: subject)
|
2019-07-26 00:36:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
# rubocop:enable Metrics/AbcSize
|
2023-02-08 21:55:05 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def t(key, **args)
|
|
|
|
I18n.t("deploy_mailer.deployed#{key}", **args)
|
|
|
|
end
|
2019-07-26 00:36:33 +00:00
|
|
|
end
|