2020-03-23 20:46:19 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Envía los mensajes de contacto
|
|
|
|
class ContactJob < ApplicationJob
|
|
|
|
def perform(**args)
|
2020-03-25 18:50:07 +00:00
|
|
|
@params = args
|
|
|
|
|
2020-05-30 19:43:25 +00:00
|
|
|
# Sanitizar los valores
|
|
|
|
args[:form].keys.each do |key|
|
|
|
|
args[:form][key] = ActionController::Base.helpers.sanitize args[:form][key]
|
|
|
|
end
|
|
|
|
|
2020-03-25 18:50:07 +00:00
|
|
|
# Enviar de a 10 usuaries para minimizar el riesgo que nos
|
|
|
|
# consideren spammers.
|
|
|
|
#
|
|
|
|
# TODO: #i18n. Agrupar usuaries por su idioma
|
|
|
|
|
|
|
|
usuaries.each_slice(10) do |u|
|
2020-05-30 19:43:25 +00:00
|
|
|
ContactMailer.with(**args.merge(usuaries_emails: u))
|
2020-03-25 18:50:07 +00:00
|
|
|
.notify_usuaries.deliver_now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Trae solo les usuaries definitives para eliminar un vector de ataque
|
|
|
|
# donde alguien crea un sitio, agrega a muches usuaries y les envía
|
|
|
|
# correos.
|
|
|
|
#
|
|
|
|
# TODO: Mover a Site#usuaries
|
|
|
|
def usuaries
|
|
|
|
site.roles.where(rol: 'usuarie', temporal: false).includes(:usuarie)
|
|
|
|
.pluck(:email)
|
2020-03-23 20:46:19 +00:00
|
|
|
end
|
|
|
|
end
|