diff --git a/app/services/child_service.rb b/app/services/child_service.rb index e589a9f54..45ebd1a4c 100644 --- a/app/services/child_service.rb +++ b/app/services/child_service.rb @@ -7,13 +7,38 @@ class ChildService NotificationCenter.call type: 'notify_admin_child_created', receiver: User.admins_and_managers, attached_object: child + all_files_are_upload = true + SupportingDocumentType.where(document_type: 'Child').each do |sdt| + file = sdt.supporting_document_files.find_by(supportable: child) + all_files_are_upload = false if file.nil? || file.attachment_identifier.nil? + end + if all_files_are_upload + NotificationCenter.call type: 'notify_admin_user_child_supporting_document_files_created', + receiver: User.admins_and_managers, + attached_object: child + end + return true end false end def self.update(child, child_params) - child.update(child_params) + if child.update(child_params) + all_files_are_upload = true + SupportingDocumentType.where(document_type: 'Child').each do |sdt| + file = sdt.supporting_document_files.find_by(supportable: child) + all_files_are_upload = false if file.nil? || file.attachment_identifier.nil? + end + if all_files_are_upload + NotificationCenter.call type: 'notify_admin_user_child_supporting_document_files_updated', + receiver: User.admins_and_managers, + attached_object: child + end + + return true + end + false end def self.validate(child, is_valid) diff --git a/app/views/api/notifications/_notify_admin_user_child_supporting_document_files_created.json.jbuilder b/app/views/api/notifications/_notify_admin_user_child_supporting_document_files_created.json.jbuilder new file mode 100644 index 000000000..4a16e4502 --- /dev/null +++ b/app/views/api/notifications/_notify_admin_user_child_supporting_document_files_created.json.jbuilder @@ -0,0 +1,3 @@ +json.title notification.notification_type +json.description t('.supporting_document_files_uploaded', + NAME: notification.attached_object&.full_name || t('api.notifications.deleted_user')) diff --git a/app/views/api/notifications/_notify_admin_user_child_supporting_document_files_updated.json.jbuilder b/app/views/api/notifications/_notify_admin_user_child_supporting_document_files_updated.json.jbuilder new file mode 100644 index 000000000..5b97b34ea --- /dev/null +++ b/app/views/api/notifications/_notify_admin_user_child_supporting_document_files_updated.json.jbuilder @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +json.title notification.notification_type +json.description t('.supporting_document_files_uploaded', + NAME: notification.attached_object&.full_name || t('api.notifications.deleted_user')) diff --git a/app/views/notifications_mailer/notify_admin_user_child_supporting_document_files_created.html.erb b/app/views/notifications_mailer/notify_admin_user_child_supporting_document_files_created.html.erb new file mode 100644 index 000000000..239915785 --- /dev/null +++ b/app/views/notifications_mailer/notify_admin_user_child_supporting_document_files_created.html.erb @@ -0,0 +1,18 @@ +<%= render 'notifications_mailer/shared/hello', recipient: @recipient %> + +

+ <%= t('.body.supporting_document_files_uploaded_below', + NAME: @attached_object&.full_name || t('api.notifications.deleted_user')) %> +

+ +<% if Setting.get('child_validation_required') %> +

+ <%= t('.body.validate_child') %> +

+<% end %> diff --git a/app/views/notifications_mailer/notify_admin_user_child_supporting_document_files_updated.html.erb b/app/views/notifications_mailer/notify_admin_user_child_supporting_document_files_updated.html.erb new file mode 100644 index 000000000..00355c465 --- /dev/null +++ b/app/views/notifications_mailer/notify_admin_user_child_supporting_document_files_updated.html.erb @@ -0,0 +1,19 @@ +<%= render 'notifications_mailer/shared/hello', recipient: @recipient %> + +

+ <%= t('.body.child_update_supporting_document_file', + NAME: @attached_object&.full_name || t('api.notifications.deleted_user')) %> +

+ + +<% if Setting.get('child_validation_required') %> +

+ <%= t('.body.validate_child') %> +

+<% end %> diff --git a/config/locales/app.logged.en.yml b/config/locales/app.logged.en.yml index 69afbfbd7..f284fbc5d 100644 --- a/config/locales/app.logged.en.yml +++ b/config/locales/app.logged.en.yml @@ -295,6 +295,8 @@ en: notify_admin_user_child_supporting_document_refusal: "A supporting document of child has been rejected" notify_admin_user_supporting_document_files_created: "A user has uploaded a supporting document" notify_admin_user_supporting_document_files_updated: "A user has updated a supporting document" + notify_admin_user_child_supporting_document_files_created: "A child has uploaded a supporting document" + notify_admin_user_child_supporting_document_files_updated: "A child has updated a supporting document" notify_admin_member_create_reservation: "A member books a reservation" notify_admin_slot_is_modified: "A reservation slot has been modified" notify_admin_slot_is_canceled: "A reservation has been cancelled" diff --git a/config/locales/app.logged.fr.yml b/config/locales/app.logged.fr.yml index 0dc9c03f0..24550f9d1 100644 --- a/config/locales/app.logged.fr.yml +++ b/config/locales/app.logged.fr.yml @@ -295,6 +295,8 @@ fr: notify_admin_user_child_supporting_document_refusal: "Un justificatif de l'enfant a été refusé" notify_admin_user_supporting_document_files_created: "Un utilisateur a téléversé un justificatif" notify_admin_user_supporting_document_files_updated: "Un utilisateur a mis à jour un justificatif" + notify_admin_user_child_supporting_document_files_created: "Un enfant a téléversé un justificatif" + notify_admin_user_child_supporting_document_files_updated: "Un enfant a mis à jour un justificatif" notify_admin_member_create_reservation: "Un membre fait une réservation" notify_admin_slot_is_modified: "Un créneau de réservation a été modifié" notify_admin_slot_is_canceled: "Une réservation a été annulée" diff --git a/config/locales/en.yml b/config/locales/en.yml index bfa86abbe..911c463d0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -443,6 +443,10 @@ en: supporting_document_files_uploaded: "Supporting document uploaded by member %{NAME}." notify_admin_user_supporting_document_files_updated: supporting_document_files_uploaded: "Supporting document changed by member %{NAME}." + notify_admin_user_child_supporting_document_files_created: + supporting_document_files_uploaded: "Child's %{NAME} supporting document uploaded." + notify_admin_user_child_supporting_document_files_updated: + supporting_document_files_uploaded: "Supporting document changed by child %{NAME}." notify_user_is_validated: account_validated: "Your account is valid." notify_user_is_invalidated: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 8961745e6..96384e6d4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -443,6 +443,10 @@ fr: supporting_document_files_uploaded: "Le membre %{NAME} a téléversé un nouveau justificatif." notify_admin_user_supporting_document_files_updated: supporting_document_files_uploaded: "Le membre %{NAME} a modifié un justificatif." + notify_admin_user_child_supporting_document_files_created: + supporting_document_files_uploaded: "L'enfant %{NAME} a téléversé un nouveau justificatif." + notify_admin_user_child_supporting_document_files_updated: + supporting_document_files_uploaded: "L'enfant %{NAME} a modifié un justificatif." notify_user_is_validated: account_validated: "Votre compte est valide." notify_user_is_invalidated: diff --git a/config/locales/mails.en.yml b/config/locales/mails.en.yml index bf2c74d02..0d6ca6a84 100644 --- a/config/locales/mails.en.yml +++ b/config/locales/mails.en.yml @@ -393,6 +393,16 @@ en: body: user_update_supporting_document_file: "Member %{NAME} has modified the supporting documents below:" validate_user: "Please validate this account" + notify_admin_user_child_supporting_document_files_created: + subject: "Supporting documents of child uploaded by a member" + body: + supporting_document_files_uploaded_below: "Child %{NAME} has uploaded the following supporting documents:" + validate_child: "Please validate this child account" + notify_admin_user_child_supporting_document_files_updated: + subject: "Child's supporting documents have changed" + body: + child_update_supporting_document_file: "Child %{NAME} has modified the supporting documents below:" + validate_child: "Please validate this child account" notify_user_is_validated: subject: "Account validated" body: diff --git a/config/locales/mails.fr.yml b/config/locales/mails.fr.yml index 69e10ab97..60bfe3be1 100644 --- a/config/locales/mails.fr.yml +++ b/config/locales/mails.fr.yml @@ -393,6 +393,16 @@ fr: body: user_update_supporting_document_file: "Le membre %{NAME} a modifié le justificatif ci-dessous :" validate_user: "Veuillez valider son compte" + notify_admin_user_child_supporting_document_files_created: + subject: "Justificatif de l'enfant téléversé par un membre" + body: + supporting_document_files_uploaded_below: "L'enfant %{NAME} a téléversé le justificatif suivant :" + validate_child: "Veuillez valider son compte enfant" + notify_admin_user_child_supporting_document_files_updated: + subject: "Le justificatif d'un enfant a changé" + body: + child_update_supporting_document_file: "L'enfant %{NAME} a modifié le justificatif ci-dessous :" + validate_child: "Veuillez valider son compte enfant" notify_user_is_validated: subject: "Compte validé" body: diff --git a/db/seeds/notification_types.rb b/db/seeds/notification_types.rb index 5cd95f461..d5fe045ba 100644 --- a/db/seeds/notification_types.rb +++ b/db/seeds/notification_types.rb @@ -71,3 +71,19 @@ unless NotificationType.find_by(name: 'notify_user_child_is_invalidated') is_configurable: false ) end + +unless NotificationType.find_by(name: 'notify_admin_user_child_supporting_document_files_updated') + NotificationType.create!( + name: 'notify_admin_user_child_supporting_document_files_updated', + category: 'supporting_documents', + is_configurable: true + ) +end + +unless NotificationType.find_by(name: 'notify_admin_user_child_supporting_document_files_created') + NotificationType.create!( + name: 'notify_admin_user_child_supporting_document_files_created', + category: 'supporting_documents', + is_configurable: true + ) +end