diff --git a/app/frontend/src/javascript/api/notification_types.ts b/app/frontend/src/javascript/api/notification_types.ts index 4ff40150a..ccd0b4837 100644 --- a/app/frontend/src/javascript/api/notification_types.ts +++ b/app/frontend/src/javascript/api/notification_types.ts @@ -4,8 +4,8 @@ import { NotificationTypeIndexFilter, NotificationType } from '../models/notific import ApiLib from '../lib/api'; export default class NotificationTypesAPI { - static async index (isConfigurable?:NotificationTypeIndexFilter): Promise> { - const res: AxiosResponse> = await apiClient.get(`/api/notification_types${ApiLib.filtersToQuery(isConfigurable)}`); + static async index (filters?:NotificationTypeIndexFilter): Promise> { + const res: AxiosResponse> = await apiClient.get(`/api/notification_types${ApiLib.filtersToQuery(filters)}`); return res?.data; } } diff --git a/app/frontend/src/javascript/components/notifications/notifications-settings.tsx b/app/frontend/src/javascript/components/notifications/notifications-settings.tsx index 0e5a0ed4c..688774d8b 100644 --- a/app/frontend/src/javascript/components/notifications/notifications-settings.tsx +++ b/app/frontend/src/javascript/components/notifications/notifications-settings.tsx @@ -1,7 +1,8 @@ import { Loader } from '../base/loader'; import { useEffect, useState } from 'react'; import NotificationPreferencesAPI from '../../api/notification_preference'; -import { NotificationPreference, NotificationCategoryNames, NotificationPreferencesByCategories } from '../../models/notification-preference'; +import { NotificationPreference, NotificationPreferencesByCategories } from '../../models/notification-preference'; +import { NotificationCategoryNames } from '../../models/notification-type'; import { NotificationsCategory } from './notifications-category'; import NotificationTypesAPI from '../../api/notification_types'; @@ -28,7 +29,7 @@ const NotificationsSettings: React.FC = ({ onError } NotificationTypesAPI.index({ is_configurable: true }) .then(notificationTypes => { - // Initialize an object with every categories as keys + // Initialize an object with every category as keys const newPreferencesByCategories: NotificationPreferencesByCategories = {}; for (const categoryName of NotificationCategoryNames) { newPreferencesByCategories[categoryName] = []; diff --git a/app/frontend/src/javascript/models/notification-preference.ts b/app/frontend/src/javascript/models/notification-preference.ts index 7bcababf2..ccf9b1858 100644 --- a/app/frontend/src/javascript/models/notification-preference.ts +++ b/app/frontend/src/javascript/models/notification-preference.ts @@ -1,25 +1,10 @@ +import { NotificationTypeName, NotificationCategoryName } from './notification-type'; + export interface NotificationPreference { id: number, - notification_type: string, + notification_type: NotificationTypeName, email: boolean, in_system: boolean } -// This controls the order of the categories' display in the notification center -export const NotificationCategoryNames = [ - 'users_accounts', - 'proof_of_identity', - 'agenda', - 'subscriptions', - 'payments', - 'wallet', - 'shop', - 'projects', - 'accountings', - 'trainings', - 'app_management' -] as const; - -export type NotificationCategoryName = typeof NotificationCategoryNames[number]; - export type NotificationPreferencesByCategories = Record> | Record diff --git a/app/frontend/src/javascript/models/notification-type.ts b/app/frontend/src/javascript/models/notification-type.ts index b1a310026..14f6f4db6 100644 --- a/app/frontend/src/javascript/models/notification-type.ts +++ b/app/frontend/src/javascript/models/notification-type.ts @@ -1,9 +1,9 @@ -import { ApiFilter } from '../models/api'; +import { ApiFilter } from './api'; export interface NotificationType { id: number, - name: typeof notificationTypeNames[number], - category: string, + name: NotificationTypeName, + category: NotificationCategoryName, is_configurable: boolean } @@ -69,15 +69,34 @@ export const notificationTypeNames = [ 'notify_member_payment_schedule_error', 'notify_admin_payment_schedule_gateway_canceled', 'notify_member_payment_schedule_gateway_canceled', - 'notify_admin_user_proof_of_identity_files_created', - 'notify_admin_user_proof_of_identity_files_updated', + 'notify_admin_user_supporting_document_files_created', + 'notify_admin_user_supporting_document_files_updated', 'notify_user_is_validated', 'notify_user_is_invalidated', 'notify_user_proof_of_identity_refusal', - 'notify_admin_user_proof_of_identity_refusal', + 'notify_admin_user_supporting_document_refusal', 'notify_user_order_is_ready', 'notify_user_order_is_canceled', 'notify_user_order_is_refunded', 'notify_admin_low_stock_threshold', 'notify_admin_training_auto_cancelled' ] as const; + +export type NotificationTypeName = typeof notificationTypeNames[number]; + +// This controls the order of the categories' display in the notification center +export const NotificationCategoryNames = [ + 'users_accounts', + 'supporting_documents', + 'agenda', + 'subscriptions', + 'payments', + 'wallet', + 'shop', + 'projects', + 'accountings', + 'trainings', + 'app_management' +] as const; + +export type NotificationCategoryName = typeof NotificationCategoryNames[number]; diff --git a/app/models/notification_type.rb b/app/models/notification_type.rb index 745db1940..1b90d3fef 100644 --- a/app/models/notification_type.rb +++ b/app/models/notification_type.rb @@ -12,6 +12,7 @@ class NotificationType < ApplicationRecord has_many :notification_preferences, dependent: :destroy validates :name, uniqueness: true, presence: true - validates :category, presence: true + validates :category, presence: true, inclusion: { in: %w[subscriptions user projects deprecated exports agenda trainings accountings + app_management wallet payments users_accounts supporting_documents shop] } validates :is_configurable, inclusion: { in: [true, false] } end diff --git a/app/services/proof_of_identity_file_service.rb b/app/services/proof_of_identity_file_service.rb index ad4164837..50c4997f4 100644 --- a/app/services/proof_of_identity_file_service.rb +++ b/app/services/proof_of_identity_file_service.rb @@ -4,10 +4,8 @@ class ProofOfIdentityFileService def self.list(operator, filters = {}) files = [] - if filters[:user_id].present? - if operator.privileged? || filters[:user_id].to_i == operator.id - files = ProofOfIdentityFile.where(user_id: filters[:user_id]) - end + if filters[:user_id].present? && (operator.privileged? || filters[:user_id].to_i == operator.id) + files = ProofOfIdentityFile.where(user_id: filters[:user_id]) end files end @@ -20,12 +18,10 @@ class ProofOfIdentityFileService all_files_are_upload = true user.group.proof_of_identity_types.each do |type| file = type.proof_of_identity_files.find_by(user_id: proof_of_identity_file.user_id) - unless file - all_files_are_upload = false - end + all_files_are_upload = false unless file end if all_files_are_upload - NotificationCenter.call type: 'notify_admin_user_proof_of_identity_files_created', + NotificationCenter.call type: 'notify_admin_user_supporting_document_files_created', receiver: User.admins_and_managers, attached_object: user end @@ -40,12 +36,10 @@ class ProofOfIdentityFileService all_files_are_upload = true user.group.proof_of_identity_types.each do |type| file = type.proof_of_identity_files.find_by(user_id: proof_of_identity_file.user_id) - unless file - all_files_are_upload = false - end + all_files_are_upload = false unless file end if all_files_are_upload && !user.validated_at? - NotificationCenter.call type: 'notify_admin_user_proof_of_identity_files_updated', + NotificationCenter.call type: 'notify_admin_user_supporting_document_files_updated', receiver: User.admins_and_managers, attached_object: proof_of_identity_file end diff --git a/app/services/proof_of_identity_refusal_service.rb b/app/services/proof_of_identity_refusal_service.rb index 4c8416b91..1edaac13a 100644 --- a/app/services/proof_of_identity_refusal_service.rb +++ b/app/services/proof_of_identity_refusal_service.rb @@ -4,9 +4,7 @@ class ProofOfIdentityRefusalService def self.list(filters = {}) refusals = [] - if filters[:user_id].present? - files = ProofOfIdentityRefusal.where(user_id: filters[:user_id]) - end + refusals = ProofOfIdentityRefusal.where(user_id: filters[:user_id]) if filters[:user_id].present? refusals end @@ -14,7 +12,7 @@ class ProofOfIdentityRefusalService saved = proof_of_identity_refusal.save if saved - NotificationCenter.call type: 'notify_admin_user_proof_of_identity_refusal', + NotificationCenter.call type: 'notify_admin_user_supporting_document_refusal', receiver: User.admins_and_managers, attached_object: proof_of_identity_refusal NotificationCenter.call type: 'notify_user_proof_of_identity_refusal', diff --git a/app/views/api/notifications/_notify_admin_user_proof_of_identity_files_created.json.jbuilder b/app/views/api/notifications/_notify_admin_user_supporting_document_files_created.json.jbuilder similarity index 72% rename from app/views/api/notifications/_notify_admin_user_proof_of_identity_files_created.json.jbuilder rename to app/views/api/notifications/_notify_admin_user_supporting_document_files_created.json.jbuilder index d075018b0..9a80540f1 100644 --- a/app/views/api/notifications/_notify_admin_user_proof_of_identity_files_created.json.jbuilder +++ b/app/views/api/notifications/_notify_admin_user_supporting_document_files_created.json.jbuilder @@ -1,3 +1,3 @@ json.title notification.notification_type -json.description t('.proof_of_identity_files_uploaded', +json.description t('.supporting_document_files_uploaded', NAME: notification.attached_object&.profile&.full_name || t('api.notifications.deleted_user')) diff --git a/app/views/api/notifications/_notify_admin_user_proof_of_identity_files_updated.json.jbuilder b/app/views/api/notifications/_notify_admin_user_supporting_document_files_updated.json.jbuilder similarity index 64% rename from app/views/api/notifications/_notify_admin_user_proof_of_identity_files_updated.json.jbuilder rename to app/views/api/notifications/_notify_admin_user_supporting_document_files_updated.json.jbuilder index 1ffa0c347..0f85e7d9b 100644 --- a/app/views/api/notifications/_notify_admin_user_proof_of_identity_files_updated.json.jbuilder +++ b/app/views/api/notifications/_notify_admin_user_supporting_document_files_updated.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.title notification.notification_type -json.description t('.proof_of_identity_files_uploaded', +json.description t('.supporting_document_files_uploaded', NAME: notification.attached_object&.user&.profile&.full_name || t('api.notifications.deleted_user')) diff --git a/app/views/api/notifications/_notify_admin_user_proof_of_identity_refusal.json.jbuilder b/app/views/api/notifications/_notify_admin_user_supporting_document_refusal.json.jbuilder similarity index 86% rename from app/views/api/notifications/_notify_admin_user_proof_of_identity_refusal.json.jbuilder rename to app/views/api/notifications/_notify_admin_user_supporting_document_refusal.json.jbuilder index 1fa287c30..93fb21f32 100644 --- a/app/views/api/notifications/_notify_admin_user_proof_of_identity_refusal.json.jbuilder +++ b/app/views/api/notifications/_notify_admin_user_supporting_document_refusal.json.jbuilder @@ -1,3 +1,5 @@ +# frozen_string_literal: true + json.title notification.notification_type json.description t('.refusal', NAME: notification.attached_object&.user&.profile&.full_name || t('api.notifications.deleted_user')) diff --git a/app/views/notifications_mailer/notify_admin_user_proof_of_identity_files_created.html.erb b/app/views/notifications_mailer/notify_admin_user_supporting_document_files_created.html.erb similarity index 85% rename from app/views/notifications_mailer/notify_admin_user_proof_of_identity_files_created.html.erb rename to app/views/notifications_mailer/notify_admin_user_supporting_document_files_created.html.erb index d8bf2a4fd..1530761d4 100644 --- a/app/views/notifications_mailer/notify_admin_user_proof_of_identity_files_created.html.erb +++ b/app/views/notifications_mailer/notify_admin_user_supporting_document_files_created.html.erb @@ -1,7 +1,7 @@ <%= render 'notifications_mailer/shared/hello', recipient: @recipient %>

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

    diff --git a/app/views/notifications_mailer/notify_admin_user_proof_of_identity_files_updated.html.erb b/app/views/notifications_mailer/notify_admin_user_supporting_document_files_updated.html.erb similarity index 84% rename from app/views/notifications_mailer/notify_admin_user_proof_of_identity_files_updated.html.erb rename to app/views/notifications_mailer/notify_admin_user_supporting_document_files_updated.html.erb index 8951793ca..9052f3124 100644 --- a/app/views/notifications_mailer/notify_admin_user_proof_of_identity_files_updated.html.erb +++ b/app/views/notifications_mailer/notify_admin_user_supporting_document_files_updated.html.erb @@ -1,7 +1,7 @@ <%= render 'notifications_mailer/shared/hello', recipient: @recipient %>

    - <%= t('.body.user_update_proof_of_identity_file', + <%= t('.body.user_update_supporting_document_file', NAME: @attached_object&.user&.profile&.full_name || t('api.notifications.deleted_user')) %>

      diff --git a/app/views/notifications_mailer/notify_admin_user_proof_of_identity_refusal.html.erb b/app/views/notifications_mailer/notify_admin_user_supporting_document_refusal.html.erb similarity index 86% rename from app/views/notifications_mailer/notify_admin_user_proof_of_identity_refusal.html.erb rename to app/views/notifications_mailer/notify_admin_user_supporting_document_refusal.html.erb index b2480ddcb..d4b032bdb 100644 --- a/app/views/notifications_mailer/notify_admin_user_proof_of_identity_refusal.html.erb +++ b/app/views/notifications_mailer/notify_admin_user_supporting_document_refusal.html.erb @@ -1,7 +1,7 @@ <%= render 'notifications_mailer/shared/hello', recipient: @recipient %>

      - <%= t('.body.user_proof_of_identity_files_refusal', + <%= t('.body.user_supporting_document_files_refusal', NAME: @attached_object&.user&.profile&.full_name || t('api.notifications.deleted_user'), OPERATOR: @attached_object&.operator&.profile&.full_name || t('api.notifications.deleted_user')) %>

      diff --git a/config/locales/app.logged.en.yml b/config/locales/app.logged.en.yml index 1da3f0a90..5e5b19472 100644 --- a/config/locales/app.logged.en.yml +++ b/config/locales/app.logged.en.yml @@ -270,7 +270,7 @@ en: disable_all: "Disable all" notify_me_when: "I wish to be notified when" users_accounts: "Concerning users notifications" - proof_of_identity: "Concerning identity proofs notifications" + supporting_documents: "Concerning supporting documents notifications" agenda: "Concerning agenda notifications" subscriptions: "Concerning subscriptions notifications" payments: "Concerning payment schedules notifications" @@ -288,9 +288,9 @@ en: notify_admins_role_update: "The role of a user has changed" notify_admin_import_complete: "An import is done" notify_admin_user_group_changed: "A group has changed" - notify_admin_user_proof_of_identity_refusal: "A proof of identity has been rejected" - notify_admin_user_proof_of_identity_files_created: "A user has uploaded a proof of identity" - notify_admin_user_proof_of_identity_files_updated: "A user has updated a proof of identity" + notify_admin_user_supporting_document_refusal: "A supporting document 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_member_create_reservation: "A member creates 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/en.yml b/config/locales/en.yml index 9ab87a69e..4e3eb568d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -432,18 +432,18 @@ en: schedule_deadline: "You must cash the check for the %{DATE} deadline, for schedule %{REFERENCE}" notify_admin_payment_schedule_transfer_deadline: schedule_deadline: "You must confirm the bank direct debit for the %{DATE} deadline, for schedule %{REFERENCE}" - notify_admin_user_proof_of_identity_files_created: - proof_of_identity_files_uploaded: "Proof of identity uploaded by member %{NAME}." - notify_admin_user_proof_of_identity_files_updated: - proof_of_identity_files_uploaded: "Proof of identity changed by Member %{NAME}." + notify_admin_user_supporting_document_files_created: + 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_user_is_validated: account_validated: "Your account is valid." notify_user_is_invalidated: account_invalidated: "Your account is invalid." notify_user_proof_of_identity_refusal: refusal: "Your proof of identity are not accepted" - notify_admin_user_proof_of_identity_refusal: - refusal: "Member's proof of identity %{NAME} refused." + notify_admin_user_supporting_document_refusal: + refusal: "Member's supporting document %{NAME} was refused." notify_user_order_is_ready: order_ready: "Your command %{REFERENCE} is ready" notify_user_order_is_canceled: diff --git a/config/locales/mails.en.yml b/config/locales/mails.en.yml index e1cc4b683..e17a6ceb4 100644 --- a/config/locales/mails.en.yml +++ b/config/locales/mails.en.yml @@ -370,15 +370,15 @@ en: remember: "In accordance with your %{REFERENCE} payment schedule, %{AMOUNT} was due to be debited on %{DATE}." date: "This is a reminder to verify that the direct bank debit was successfull." confirm: "Please confirm the receipt of funds in your payment schedule management interface, so that the corresponding invoice will be generated." - notify_admin_user_proof_of_identity_files_created: + notify_admin_user_supporting_document_files_created: subject: "Supporting documents uploaded by a member" body: - proof_of_identity_files_uploaded_below: "Member %{NAME} has uploaded the following supporting documents:" + supporting_document_files_uploaded_below: "Member %{NAME} has uploaded the following supporting documents:" validate_user: "Please validate this account" - notify_admin_user_proof_of_identity_files_updated: + notify_admin_user_supporting_document_files_updated: subject: "Member's supporting documents have changed" body: - user_update_proof_of_identity_file: "Member %{NAME} has modified the supporting documents below:" + user_update_supporting_document_file: "Member %{NAME} has modified the supporting documents below:" validate_user: "Please validate this account" notify_user_is_validated: subject: "Account validated" @@ -393,10 +393,10 @@ en: body: user_proof_of_identity_files_refusal: "Your supporting documents were refused:" action: "Please re-upload some new supporting documents." - notify_admin_user_proof_of_identity_refusal: + notify_admin_user_supporting_document_refusal: subject: "A member's supporting documents were refused" body: - user_proof_of_identity_files_refusal: "Member %{NAME}'s supporting documents were rejected by %{OPERATOR}:" + user_supporting_document_files_refusal: "Member %{NAME}'s supporting documents were rejected by %{OPERATOR}:" shared: hello: "Hello %{user_name}" notify_user_order_is_ready: diff --git a/db/migrate/20230126160900_create_notification_types.rb b/db/migrate/20230126160900_create_notification_types.rb index 2f330ec91..26a76cf86 100644 --- a/db/migrate/20230126160900_create_notification_types.rb +++ b/db/migrate/20230126160900_create_notification_types.rb @@ -70,19 +70,19 @@ class CreateNotificationTypes < ActiveRecord::Migration[5.2] { id: 55, name: 'notify_member_payment_schedule_error', category: 'payments', is_configurable: false }, { id: 56, name: 'notify_admin_payment_schedule_gateway_canceled', category: 'payments', is_configurable: true }, { id: 57, name: 'notify_member_payment_schedule_gateway_canceled', category: 'payments', is_configurable: false }, - { id: 58, name: 'notify_admin_user_proof_of_identity_files_created', category: 'proof_of_identity', is_configurable: true }, - { id: 59, name: 'notify_admin_user_proof_of_identity_files_updated', category: 'proof_of_identity', is_configurable: true }, + { id: 58, name: 'notify_admin_user_supporting_document_files_created', category: 'supporting_documents', is_configurable: true }, + { id: 59, name: 'notify_admin_user_supporting_document_files_updated', category: 'supporting_documents', is_configurable: true }, { id: 60, name: 'notify_user_is_validated', category: 'users_accounts', is_configurable: false }, { id: 61, name: 'notify_user_is_invalidated', category: 'users_accounts', is_configurable: false }, - { id: 62, name: 'notify_user_proof_of_identity_refusal', category: 'proof_of_identity', is_configurable: false }, - { id: 63, name: 'notify_admin_user_proof_of_identity_refusal', category: 'proof_of_identity', is_configurable: true }, + { id: 62, name: 'notify_user_proof_of_identity_refusal', category: 'supporting_documents', is_configurable: false }, + { id: 63, name: 'notify_admin_user_supporting_document_refusal', category: 'supporting_documents', is_configurable: true }, { id: 64, name: 'notify_user_order_is_ready', category: 'shop', is_configurable: true }, { id: 65, name: 'notify_user_order_is_canceled', category: 'shop', is_configurable: true }, { id: 66, name: 'notify_user_order_is_refunded', category: 'shop', is_configurable: true }, { id: 67, name: 'notify_admin_low_stock_threshold', category: 'shop', is_configurable: true }, { id: 68, name: 'notify_admin_training_auto_cancelled', category: 'trainings', is_configurable: true }, - { id: 69, name: 'notify_member_training_auto_cancelled', category: 'trainings', is_configurable: true } + { id: 69, name: 'notify_member_training_auto_cancelled', category: 'trainings', is_configurable: false } ].freeze def up diff --git a/db/seeds/notification_types.rb b/db/seeds/notification_types.rb new file mode 100644 index 000000000..202fcaf26 --- /dev/null +++ b/db/seeds/notification_types.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +unless NotificationType.find_by(name: 'notify_member_training_authorization_expired') + NotificationType.create!( + name: 'notify_member_training_authorization_expired', + category: 'trainings', + is_configurable: false + ) +end + +unless NotificationType.find_by(name: 'notify_member_training_invalidated') + NotificationType.create!( + name: 'notify_member_training_invalidated', + category: 'trainings', + is_configurable: false + ) +end diff --git a/test/fixtures/notification_types.yml b/test/fixtures/notification_types.yml index b8d8bae43..14273c1f1 100644 --- a/test/fixtures/notification_types.yml +++ b/test/fixtures/notification_types.yml @@ -456,16 +456,16 @@ notification_type_57: notification_type_58: id: 58 - name: notify_admin_user_proof_of_identity_files_created - category: proof_of_identity + name: notify_admin_user_supporting_document_files_created + category: supporting_documents is_configurable: true created_at: 2023-02-02 08:25:33.435886000 Z updated_at: 2023-02-02 08:25:33.435886000 Z notification_type_59: id: 59 - name: notify_admin_user_proof_of_identity_files_updated - category: proof_of_identity + name: notify_admin_user_supporting_document_files_updated + category: supporting_documents is_configurable: true created_at: 2023-02-02 08:25:33.436627000 Z updated_at: 2023-02-02 08:25:33.436627000 Z @@ -489,15 +489,15 @@ notification_type_61: notification_type_62: id: 62 name: notify_user_proof_of_identity_refusal - category: proof_of_identity + category: supporting_documents is_configurable: false created_at: 2023-02-02 08:25:33.439078000 Z updated_at: 2023-02-02 08:25:33.439078000 Z notification_type_63: id: 63 - name: notify_admin_user_proof_of_identity_refusal - category: proof_of_identity + name: notify_admin_user_supporting_document_refusal + category: supporting_documents is_configurable: true created_at: 2023-02-02 08:25:33.439926000 Z updated_at: 2023-02-02 08:25:33.439926000 Z