diff --git a/app/views/api/notifications/_notify_user_when_child_age_will_be_18.json.jbuilder b/app/views/api/notifications/_notify_user_when_child_age_will_be_18.json.jbuilder new file mode 100644 index 000000000..348b47f06 --- /dev/null +++ b/app/views/api/notifications/_notify_user_when_child_age_will_be_18.json.jbuilder @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +json.title notification.notification_type +json.description t('.child_age_will_be_18_years_ago', + NAME: notification.attached_object.full_name, + DATE: I18n.l(notification.attached_object.birthday, format: :default)) diff --git a/app/views/notifications_mailer/notify_user_when_child_age_will_be_18.html.erb b/app/views/notifications_mailer/notify_user_when_child_age_will_be_18.html.erb new file mode 100644 index 000000000..cb845ff68 --- /dev/null +++ b/app/views/notifications_mailer/notify_user_when_child_age_will_be_18.html.erb @@ -0,0 +1,6 @@ +<%= render 'notifications_mailer/shared/hello', recipient: @recipient %> + +<%= t('.body.child_age_will_be_18_years_ago', **{ + NAME: @attached_object.full_name, + DATE: I18n.l(@attached_object.birthday, format: :default), +}) %> diff --git a/app/workers/child_age_worker.rb b/app/workers/child_age_worker.rb new file mode 100644 index 000000000..374b451bf --- /dev/null +++ b/app/workers/child_age_worker.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# send a notification if child age > 18 years ago +class ChildAgeWorker + include Sidekiq::Worker + + def perform + children = Child.where('birthday = ?', 18.years.ago + 2.days) + children.each do |child| + NotificationCenter.call type: 'notify_user_when_child_age_will_be_18', + receiver: child.user, + attached_object: child + end + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 3673dd092..92c110377 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -481,6 +481,8 @@ en: your_reservation_RESERVABLE_was_invalidated_html: "Your pre-registration of %{RESERVABLE} wasn't validated." notify_admin_reservation_invalidated: a_RESERVABLE_reservation_was_invalidated_html: "A %{RESERVABLE} pre-registration of %{USER} was invalidated." + notify_user_when_child_age_will_be_18: + child_age_will_be_18_years_ago: "Your child %{NAME} will turn 18 on %{DATE}, at which point they will be automatically detached from your Family account. They will need to create their own account in order to make reservations." #statistics tools for admins statistics: subscriptions: "Subscriptions" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index ff6506e9f..d94ecc30f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -481,6 +481,8 @@ fr: your_reservation_RESERVABLE_was_invalidated_html: "Votre demande de pré-inscription de %{RESERVABLE} n'a pas été validée." notify_admin_reservation_invalidated: a_RESERVABLE_reservation_was_invalidated_html: "La réservation de %{RESERVABLE} de %{NAME} a été invalidée." + notify_user_when_child_age_will_be_18: + child_age_will_be_18_years_ago: "Votre enfant %{NAME} va avoir 18ans, le %{DATE}, date à laquelle il sera automatiquement détaché de votre compte Famille. Il devra se créer son propre compte pour effectuer ses réservations." #statistics tools for admins statistics: subscriptions: "Abonnements" diff --git a/config/locales/mails.en.yml b/config/locales/mails.en.yml index c3c927dc9..20f6bc39d 100644 --- a/config/locales/mails.en.yml +++ b/config/locales/mails.en.yml @@ -479,3 +479,7 @@ en: subject: "Pre-registration wasn't validated" body: reservation_invalidated_html: "%{RESERVABLE} of %{NAME} wasn't validated." + notify_user_when_child_age_will_be_18: + subject: "Your child will be 18 years old" + body: + child_age_will_be_18_years_ago: "Your child %{NAME} will turn 18 on %{DATE}, at which point they will be automatically detached from your Family account. They will need to create their own account in order to make reservations." diff --git a/config/locales/mails.fr.yml b/config/locales/mails.fr.yml index 232c48669..a6cda1010 100644 --- a/config/locales/mails.fr.yml +++ b/config/locales/mails.fr.yml @@ -479,3 +479,7 @@ fr: subject: "Demande of pré-inscription n'a pas été validée" body: reservation_invalidated_html: "%{RESERVABLE} du membre %{NAME} n'a pas été validée." + notify_user_when_child_age_will_be_18: + subject: "Votre enfant va avoir 18ans" + body: + child_age_will_be_18_years_ago: "Votre enfant %{NAME} va avoir 18ans, le %{DATE}, date à laquelle il sera automatiquement détaché de votre compte Famille. Il devra se créer son propre compte pour effectuer ses réservations." diff --git a/config/schedule.yml b/config/schedule.yml index 31e0c7f81..93b45c9e9 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -62,4 +62,9 @@ auto_cancel_authorizations: class: TrainingAuthorizationWorker queue: default +child_age_will_be_18: + cron: "0 0 0 * * *" # every day, at midnight + class: ChildAgeWorker + queue: default + <%= PluginRegistry.insert_code('yml.schedule') %> diff --git a/db/seeds/notification_types.rb b/db/seeds/notification_types.rb index 1f768bb60..582b4a030 100644 --- a/db/seeds/notification_types.rb +++ b/db/seeds/notification_types.rb @@ -94,7 +94,8 @@ NOTIFICATIONS_TYPES = [ { name: 'notify_member_pre_booked_reservation', category: 'agenda', is_configurable: false }, { name: 'notify_admin_member_pre_booked_reservation', category: 'agenda', is_configurable: true }, { name: 'notify_member_reservation_invalidated', category: 'agenda', is_configurable: false }, - { name: 'notify_admin_reservation_invalidated', category: 'agenda', is_configurable: true } + { name: 'notify_admin_reservation_invalidated', category: 'agenda', is_configurable: true }, + { name: 'notify_user_when_child_age_will_be_18', category: 'users_accounts', is_configurable: false }, ].freeze NOTIFICATIONS_TYPES.each do |notification_type|