-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ticket Mailers * added reminder job and config
- Loading branch information
Showing
24 changed files
with
281 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,4 @@ gem "hamlit" | |
gem "pagy" | ||
gem "bulmacomp" | ||
gem "csv" | ||
gem "icalendar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This job send a reminder for the next day happening | ||
class ReminderJob < ApplicationJob | ||
queue_as :default | ||
|
||
# Send the reminder | ||
# @return [Boolean] `true` if executed, `false` if ENV `RAILS_REMINDER` is not set as "true" | ||
def perform | ||
return false unless ENV.fetch('RAILS_REMINDER', 'false') == 'true' | ||
happenings = Happening.where start_at: (Time.zone.tomorrow.beginning_of_day..Time.zone.tomorrow.end_of_day) | ||
happenings.each do |happening| | ||
happening.users do |user| | ||
TicketMailer.reminder(happening.user).deliver_later | ||
end | ||
end | ||
true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
# This class define the default options for send emails | ||
class ApplicationMailer < ActionMailer::Base | ||
default from: "[email protected]" | ||
default from: ENV.fetch("RAILS_EMAIL_FROM", "[email protected]") | ||
layout "mailer" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# This class send collect the tickets notification | ||
class TicketMailer < ApplicationMailer | ||
# Send confirmation email for a ticket | ||
# @param ticket [Object] istance of created {Ticket} | ||
def confirm(ticket) | ||
@ticket = ticket | ||
@happening = @ticket.happening | ||
mail to: @ticket.user.email, subject: subject(action: 'confirm', date: @happening.start_at) | ||
end | ||
|
||
# Send notify email on destroy ticket | ||
# @param ticket [Object] istance of destroyed {Ticket} | ||
def deleted(ticket) | ||
@ticket = ticket | ||
@happening = @ticket.happening | ||
@tickets = Ticket.where(user: ticket.user, happening: ticket.happening) | ||
mail to: @ticket.user.email, subject: subject(action: 'deleted', date: @happening.start_at) | ||
end | ||
|
||
# Send reminder for an event happeningf | ||
# @param happening [Object] Istance of {Happening} to remind | ||
# @param user [Object] Istance of {User} send remind. If user have not ticket the remind is not sended | ||
def reminder(happening, user) | ||
@happening = happening | ||
@user = user | ||
@counter = @happening.tickets.with_user(@user).count | ||
mail to: @user.email, subject: subject(action: 'reminder', date: @happening.start_at) if @counter > 0 | ||
end | ||
|
||
private | ||
|
||
# make email subject with site title, action text, date of referenced happening | ||
# @param action [String] optional action name to add a locale path on subject: `reminder` -> `mailer.ticket.reminder.action`. | ||
# @param date [Date,DateTime] If present append the localized date / datetime on subject | ||
# @return [String] subject text | ||
# @example | ||
# subject | ||
# -> Partecipo | ||
# subject action: 'prova' | ||
# -> Partecipo - prova - 25/12/24 00:00 | ||
# subject action: 'prova', date: @happening.start_at | ||
# -> Partecipo - prova | ||
def subject(action: nil, date: nil, other: nil) | ||
title_text = ENV.fetch "RAILS_TITLE", "Partecipo" | ||
action_text = t("mailer.ticket.#{action}.action", locale: I18n.locale) if action.present? | ||
data_text = l date, format: :detailed if date.present? | ||
other_text = other if other.present? | ||
[title_text, action_text, data_text, other_text].compact.join(' - ') | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,15 +69,33 @@ def self.from_omniauth(auth) | |
user | ||
end | ||
|
||
# @return [String] gravatar url for user | ||
# Make gravatar url from email | ||
# @return [String] gravatar user url | ||
def avatar_url | ||
hash = Digest::MD5.hexdigest(email) | ||
"https://www.gravatar.com/avatar/#{hash}?s=64i&d=identicon" | ||
end | ||
|
||
# @return [String] name and/or surname if presents, otherwise return username or email | ||
# @example User without name, surname, and username | ||
# user = User.new email: '[email protected]' | ||
# user.title -> '[email protected]' | ||
# @example user with username | ||
# user = User.new email: '[email protected]', username: 'test' | ||
# user.title -> 'test' | ||
# @example user with all data | ||
# user = User.new name: 'Mario', surname: 'Rossi', username.... | ||
# user.title: 'Mario Rossi' | ||
def title | ||
name.present? || surname.present? ? [name, surname].join(" ") : username || email | ||
end | ||
|
||
private | ||
|
||
# if username is empty, set username value as email | ||
# @return [String] username value | ||
def add_username | ||
self.username = email unless username? | ||
username | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
%p Buongiorno #{@ticket.user.username} | ||
%h4.title.is-4= @ticket.happening.event.title | ||
- if @ticket.happening.title.present? | ||
%h5.subtitle.is-5= @ticket.happening.title | ||
|
||
%p Le confermiamo la prenotazione di n. <b>#{@ticket.seats}</b> per l'evento "<b>#{@ticket.happening.event.title}</b >" del #{l @ticket.happening.start_at, format: :detailed} | ||
.content | ||
%p | ||
= t "mailer.generic.hi" | ||
%b= @ticket.user.title | ||
|
||
%p | ||
= t "mailer.ticket.confirm.message" | ||
= l @ticket.happening.start_at, format: :detailed | ||
- if @ticket.answers.present? | ||
%p= t "mailer.ticket.confirm.data" | ||
%ul | ||
- @ticket.answers.each do |answer| | ||
%li= [answer.question.title, answer.value].join(': ') | ||
%p | ||
= t 'mailer.ticket.confirm.manage' | ||
= link_to happening_url(@ticket.happening, locale: I18n.locale), happening_url(@ticket.happening, locale: I18n.locale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
%p Buongiorno #{@ticket.user.username} | ||
%h4.title.is-4= @ticket.happening.event.title | ||
- if @ticket.happening.title.present? | ||
%h5.subtitle.is-5= @ticket.happening.title | ||
|
||
%p Le confermiamo l'eliminazione della prenotazione di n. <b>#{@ticket.seats}</b> per l'evento "<b>#{@ticket.happening.event.title}</b >" del #{l @ticket.happening.start_at, format: :detailed} | ||
.content | ||
%p | ||
= t "mailer.generic.hi" | ||
%b= @ticket.user.title | ||
|
||
%p | ||
= t "mailer.ticket.deleted.message" | ||
= l @ticket.happening.start_at, format: :detailed | ||
|
||
- if @tickets.present? | ||
%p= t 'mailer.ticket.deleted.counter', number: @tickets.count | ||
|
||
%p | ||
= t 'mailer.ticket.deleted.manage' | ||
= link_to happening_url(@ticket.happening, locale: I18n.locale), happening_url(@ticket.happening, locale: I18n.locale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
%h4.title.is-4= @happening.event.title | ||
- if @happening.title.present? | ||
%h5.subtitle.is-5= @happening.title | ||
|
||
.content | ||
%p | ||
= t "mailer.generic.hi" | ||
%b= @user.title | ||
|
||
%p | ||
= t "mailer.ticket.reminder.message" | ||
= l @happening.start_at, format: :detailed | ||
%p | ||
= t 'mailer.ticket.confirm.manage' | ||
= link_to happening_url(@happening, locale: I18n.locale), happening_url(@happening, locale: I18n.locale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
en: | ||
mailer: | ||
generic: | ||
hi: Hi | ||
ticket: | ||
confirm: | ||
action: Booking confirm | ||
message: Your reservation is confirmed on | ||
data: Data entered at booking | ||
manage: You can check the event details and manage bookings on | ||
deleted: | ||
action: Booking deleted | ||
message: Your reservation is deleted on | ||
manage: You can check the event details and manage bookings on | ||
counter: You have other %{number} booking for this Event | ||
reminder: | ||
action: Event Reminder | ||
message: This is a reminder for the event on | ||
manage: You can check the event details and manage bookings on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
it: | ||
mailer: | ||
generic: | ||
hi: Buongiorno | ||
ticket: | ||
confirm: | ||
action: Conferma prenotazione | ||
message: Confermiamo la sua prenotazioni del | ||
data: Dati inseriti al momento della prenotazione | ||
manage: Può visualizzare i dettagli dell'evento e gestire le prenotazioni all'indirizzo | ||
deleted: | ||
action: Eliminazione prenotazione | ||
message: È stata eliminata la sua prenotazione del | ||
manage: Può visualizzare i dettagli dell'evento e gestire le prenotazioni all'indirizzo | ||
counter: Hai altre %{number} prenotazioni attive per lo stesso evento. | ||
reminder: | ||
action: Promemoria evento | ||
message: Questo è un promemoria l'evento del | ||
manage: Può visualizzare i dettagli dell'evento e gestire le prenotazioni all'indirizzo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
production: | ||
periodic_cleanup: | ||
class: CleanSoftDeletedRecordsJob | ||
class: CleanJob | ||
queue: background | ||
args: | ||
days: ENV.fetch("RAILS_CLEAN_AFTER_DAYS", nil).to_i | ||
schedule: "0 2 * * *" | ||
# periodic_command: | ||
# command: "SoftDeletedRecord.due.delete_all" | ||
# priority: 2 | ||
# schedule: at 5am every day | ||
periodic_reminder: | ||
class: CleanSoftDeletedRecordsJob | ||
queue: background | ||
args: | ||
days: ENV.fetch("RAILS_CLEAN_AFTER_DAYS", nil).to_i | ||
schedule: "0 6 * * *" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "test_helper" | ||
|
||
class ReminderJobTest < ActiveJob::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |
Oops, something went wrong.