mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 17:51:41 +00:00
mensajes de mantenimiento con agenda
This commit is contained in:
parent
0bd7939ab9
commit
8f46d45603
15 changed files with 187 additions and 1 deletions
1
Gemfile
1
Gemfile
|
@ -50,6 +50,7 @@ gem 'friendly_id'
|
|||
gem 'hamlit-rails'
|
||||
gem 'hiredis'
|
||||
gem 'image_processing'
|
||||
gem 'icalendar'
|
||||
gem 'inline_svg'
|
||||
gem 'jekyll'
|
||||
gem 'jekyll-data', require: 'jekyll-data',
|
||||
|
|
|
@ -194,6 +194,9 @@ GEM
|
|||
http_parser.rb (0.6.0)
|
||||
i18n (1.8.3)
|
||||
concurrent-ruby (~> 1.0)
|
||||
icalendar (2.6.1)
|
||||
ice_cube (~> 0.16)
|
||||
ice_cube (0.16.3)
|
||||
image_processing (1.11.0)
|
||||
mini_magick (>= 4.9.5, < 5)
|
||||
ruby-vips (>= 2.0.17, < 3)
|
||||
|
@ -507,6 +510,7 @@ DEPENDENCIES
|
|||
haml-lint
|
||||
hamlit-rails
|
||||
hiredis
|
||||
icalendar
|
||||
image_processing
|
||||
inline_svg
|
||||
jbuilder (~> 2.5)
|
||||
|
|
30
app/jobs/maintenance_job.rb
Normal file
30
app/jobs/maintenance_job.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Envía los mensajes de mantenimiento
|
||||
#
|
||||
# TODO: Interfaz web desde el panel de gestión. Mientras tanto:
|
||||
#
|
||||
# docker exec -it sutty /bin/sh
|
||||
# su app
|
||||
# cd
|
||||
# bundle exec rails c
|
||||
# m = Maintenance.create message_en: 'reason', message_es: 'razón',
|
||||
# estimated_from: Time.now, estimated_to: Time.now + 1.hour
|
||||
# MaintenanceJob.perform_async(maintenance_id: m.id)
|
||||
#
|
||||
# Lo mismo para salir de mantenimiento, agregando el atributo
|
||||
# are_we_back: true al crear el Maintenance.
|
||||
class MaintenanceJob < ApplicationJob
|
||||
def perform(maintenance_id:)
|
||||
maintenance = Maintenance.find(maintenance_id)
|
||||
# Decidir cuál vamos a enviar según el estado de Maintenance
|
||||
mailer = maintenance.are_we_back ? :were_back : :notice
|
||||
|
||||
# XXX: Parece que [0] es más rápido que []#first
|
||||
Usuarie.all.pluck(:email, :lang).each do |u|
|
||||
MaintenanceMailer.with(maintenance: maintenance,
|
||||
email: u[0],
|
||||
lang: u[1]).send(mailer).deliver_now
|
||||
end
|
||||
end
|
||||
end
|
|
@ -20,6 +20,8 @@ class ContactMailer < ApplicationMailer
|
|||
|
||||
# El CSV es un archivo adjunto con dos filas, una con las etiquetas de
|
||||
# los campos en la cabecera y otra con los valores.
|
||||
#
|
||||
# TODO: Si el sitio tiene muches usuaries esto se genera cada vez.
|
||||
def generate_csv
|
||||
csv = ["\xEF\xBB\xBF"]
|
||||
csv << params[:form].keys.map do |field|
|
||||
|
|
46
app/mailers/maintenance_mailer.rb
Normal file
46
app/mailers/maintenance_mailer.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
# 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
|
||||
params[:maintenance] = Maintenance.find(params[:maintenance_id])
|
||||
|
||||
Usuarie.all.find_each do |usuarie|
|
||||
I18n.with_locale usuarie.lang do
|
||||
mail to: usuarie.email,
|
||||
subject: I18n.t('maintenance_mailer.were_back.subject')
|
||||
end
|
||||
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
|
8
app/models/maintenance.rb
Normal file
8
app/models/maintenance.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# En mantenimiento
|
||||
class Maintenance < ApplicationRecord
|
||||
extend Mobility
|
||||
|
||||
translates :message, type: :string, locale_accessors: true
|
||||
end
|
6
app/views/maintenance/were_back.text.haml
Normal file
6
app/views/maintenance/were_back.text.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
= t('.hi').html_safe
|
||||
\
|
||||
= t('.message').html_safe
|
||||
\
|
||||
= params[:maintenance].message.html_safe
|
||||
\
|
6
app/views/maintenance_mailer/notice.html.haml
Normal file
6
app/views/maintenance_mailer/notice.html.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
%p= t('.hi')
|
||||
%p= t('.message')
|
||||
%p= t('.reason')
|
||||
%blockquote= params[:maintenance].message
|
||||
%p= t('.estimated_from', from: params[:maintenance].estimated_from)
|
||||
%p= t('.estimated_to', to: params[:maintenance].estimated_to)
|
12
app/views/maintenance_mailer/notice.text.haml
Normal file
12
app/views/maintenance_mailer/notice.text.haml
Normal file
|
@ -0,0 +1,12 @@
|
|||
= t('.hi').html_safe
|
||||
\
|
||||
= t('.message').html_safe
|
||||
\
|
||||
= t('.reason').html_safe
|
||||
\
|
||||
= params[:maintenance].message.html_safe
|
||||
\
|
||||
= t('.estimated_from', from: params[:maintenance].estimated_from).html_safe
|
||||
\
|
||||
= t('.estimated_to', to: params[:maintenance].estimated_to).html_safe
|
||||
\
|
3
app/views/maintenance_mailer/were_back.html.haml
Normal file
3
app/views/maintenance_mailer/were_back.html.haml
Normal file
|
@ -0,0 +1,3 @@
|
|||
%p= t('.hi')
|
||||
%p= t('.message')
|
||||
%blockquote= params[:maintenance].message
|
6
app/views/maintenance_mailer/were_back.text.haml
Normal file
6
app/views/maintenance_mailer/were_back.text.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
= t('.hi')
|
||||
\
|
||||
= t('.message')
|
||||
\
|
||||
= params[:maintenance].message
|
||||
\
|
|
@ -69,6 +69,21 @@ en:
|
|||
success: Available for download
|
||||
error: Error
|
||||
help: You can contact us by replying this e-mail
|
||||
maintenance_mailer:
|
||||
notice:
|
||||
subject: 'Maintenance notice'
|
||||
hi: 'Hi!'
|
||||
message: "We're getting in contact with you to let you know we'll be doing maintenance work in our servers."
|
||||
reason: 'The reason is:'
|
||||
estimated_from: 'The maintenance period starts at %{from}'
|
||||
estimated_to: 'Up to %{to} (approximately)'
|
||||
thanks: 'Thanks for your patience'
|
||||
were_back:
|
||||
subject: 'Maintenance period ended'
|
||||
hi: 'Hi!'
|
||||
message: 'The maintenance period ended at %{created_at}'
|
||||
ics:
|
||||
summary: 'Sutty - Maintenance'
|
||||
activerecord:
|
||||
models:
|
||||
usuarie: User
|
||||
|
|
|
@ -71,6 +71,21 @@ es:
|
|||
success: Disponible para descargar
|
||||
error: Hubo un error
|
||||
help: Por cualquier duda, responde este correo para contactarte con nosotres.
|
||||
maintenance_mailer:
|
||||
notice:
|
||||
subject: 'Aviso de mantenimiento'
|
||||
hi: '¡Hola!'
|
||||
message: 'Nos comunicamos con vos para informarte que estaremos realizando mantenimiento en nuestros servidores'
|
||||
reason: 'La razón de esta tarea es:'
|
||||
estimated_from: 'El mantenimiento se realizará a partir de %{from}'
|
||||
estimated_to: 'Hasta %{to} (aproximadamente)'
|
||||
thanks: 'Gracias por tu paciencia'
|
||||
were_back:
|
||||
subject: 'Fin del mantenimiento'
|
||||
hi: '¡Hola!'
|
||||
message: 'El período de mantenimiento terminó en %{created_at}'
|
||||
ics:
|
||||
summary: 'Sutty - Mantenimiento'
|
||||
activerecord:
|
||||
models:
|
||||
usuarie: Usuarie
|
||||
|
|
14
db/migrate/20200616133218_create_maintenance.rb
Normal file
14
db/migrate/20200616133218_create_maintenance.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Crea una tabla de avisos de mantenimiento
|
||||
class CreateMaintenance < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
create_table :maintenances do |t|
|
||||
t.timestamps
|
||||
t.text :message
|
||||
t.datetime :estimated_from
|
||||
t.datetime :estimated_to
|
||||
t.boolean :are_we_back, default: false
|
||||
end
|
||||
end
|
||||
end
|
20
db/schema.rb
20
db/schema.rb
|
@ -12,7 +12,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20_200_206_151_057) do
|
||||
ActiveRecord::Schema.define(version: 20_200_616_133_218) do
|
||||
# Could not dump table "access_logs" because of following StandardError
|
||||
# Unknown type '' for column 'id'
|
||||
|
||||
|
@ -92,6 +92,23 @@ ActiveRecord::Schema.define(version: 20_200_206_151_057) do
|
|||
t.string 'icons'
|
||||
end
|
||||
|
||||
create_table 'log_entries', force: :cascade do |t|
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.integer 'site_id'
|
||||
t.text 'text'
|
||||
t.index ['site_id'], name: 'index_log_entries_on_site_id'
|
||||
end
|
||||
|
||||
create_table 'maintenances', force: :cascade do |t|
|
||||
t.datetime 'created_at', precision: 6, null: false
|
||||
t.datetime 'updated_at', precision: 6, null: false
|
||||
t.text 'message'
|
||||
t.datetime 'estimated_from'
|
||||
t.datetime 'estimated_to'
|
||||
t.boolean 'are_we_back', default: false
|
||||
end
|
||||
|
||||
create_table 'mobility_string_translations', force: :cascade do |t|
|
||||
t.string 'locale', null: false
|
||||
t.string 'key', null: false
|
||||
|
@ -139,6 +156,7 @@ ActiveRecord::Schema.define(version: 20_200_206_151_057) do
|
|||
t.text 'description'
|
||||
t.string 'title'
|
||||
t.boolean 'colaboracion_anonima', default: false
|
||||
t.boolean 'contact', default: false
|
||||
t.index ['design_id'], name: 'index_sites_on_design_id'
|
||||
t.index ['licencia_id'], name: 'index_sites_on_licencia_id'
|
||||
t.index ['name'], name: 'index_sites_on_name', unique: true
|
||||
|
|
Loading…
Reference in a new issue