mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
(feat) add a notification to remind users to upload their supporting documents
This commit is contained in:
commit
33d81c6c36
@ -4,6 +4,7 @@
|
||||
|
||||
- improves api/notification controller to avoid failing when there is a notification with wrong notification_type in db
|
||||
- Add extra_authorize_params to OpenIdConnect config
|
||||
- Improvement : add a notification to remind users to upload their supporting documents
|
||||
|
||||
## v6.0.14 2023 September 6
|
||||
|
||||
|
@ -74,6 +74,7 @@ export const notificationTypeNames = [
|
||||
'notify_user_is_validated',
|
||||
'notify_user_is_invalidated',
|
||||
'notify_user_supporting_document_refusal',
|
||||
'notify_user_supporting_document_reminder',
|
||||
'notify_admin_user_supporting_document_refusal',
|
||||
'notify_user_order_is_ready',
|
||||
'notify_user_order_is_canceled',
|
||||
|
@ -90,6 +90,7 @@ class User < ApplicationRecord
|
||||
scope :not_confirmed, -> { where(confirmed_at: nil) }
|
||||
scope :inactive_for_3_years, -> { where('users.last_sign_in_at < ?', 3.years.ago) }
|
||||
scope :not_validated, -> { where(validated_at: nil) }
|
||||
scope :supporting_documents_reminder_not_sent, -> { where(supporting_documents_reminder_sent_at: nil) }
|
||||
|
||||
def to_json(*)
|
||||
ApplicationController.new.view_context.render(
|
||||
|
@ -27,6 +27,7 @@ class Members::MembersService
|
||||
if @member.validated_at? && !(new_types - current_types).empty?
|
||||
validated_at_changed = true
|
||||
@member.validated_at = nil
|
||||
@member.supporting_documents_reminder_sent_at = nil
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.title notification.notification_type
|
||||
json.description t('.reminder_message')
|
@ -0,0 +1,5 @@
|
||||
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
|
||||
|
||||
<p>
|
||||
<%= t('.body.user_supporting_document_reminder') %>
|
||||
</p>
|
27
app/workers/supporting_documents_reminder_worker.rb
Normal file
27
app/workers/supporting_documents_reminder_worker.rb
Normal file
@ -0,0 +1,27 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Send a notification to users who did not upload their supporting document files yet
|
||||
class SupportingDocumentsReminderWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform
|
||||
users_to_notify = User.members
|
||||
.supporting_documents_reminder_not_sent
|
||||
.where("users.created_at < ?", 2.days.ago)
|
||||
.left_outer_joins(supporting_document_files: { supporting_document_type: :groups })
|
||||
.where("groups.id = users.group_id OR groups.id IS NULL")
|
||||
.select("users.*, count(supporting_document_files.id)")
|
||||
.group("users.id")
|
||||
.having("(count(supporting_document_files.id)) < (SELECT count(supporting_document_types.id) "\
|
||||
"FROM supporting_document_types "\
|
||||
"INNER JOIN supporting_document_types_groups "\
|
||||
"ON supporting_document_types_groups.supporting_document_type_id = supporting_document_types.id "\
|
||||
"WHERE supporting_document_types_groups.group_id = users.group_id)")
|
||||
users_to_notify.each do |user|
|
||||
NotificationCenter.call type: 'notify_user_supporting_document_reminder',
|
||||
receiver: user,
|
||||
attached_object: user
|
||||
user.update_column(:supporting_documents_reminder_sent_at, DateTime.current)
|
||||
end
|
||||
end
|
||||
end
|
@ -76,5 +76,6 @@ NOTIFICATIONS_TYPES = [
|
||||
{ name: 'notify_user_order_is_refunded', category: 'shop', is_configurable: false },
|
||||
{ name: 'notify_admin_low_stock_threshold', category: 'shop', is_configurable: true, roles: ['admin', 'manager'] },
|
||||
{ name: 'notify_admin_training_auto_cancelled', category: 'trainings', is_configurable: true, roles: ['admin', 'manager'] },
|
||||
{ name: 'notify_member_training_auto_cancelled', category: 'trainings', is_configurable: false }
|
||||
].freeze
|
||||
{ name: 'notify_member_training_auto_cancelled', category: 'trainings', is_configurable: false },
|
||||
{ name: 'notify_user_supporting_document_reminder', category: 'supporting_documents', is_configurable: false }
|
||||
].freeze
|
||||
|
@ -447,6 +447,8 @@ en:
|
||||
account_invalidated: "Your account is invalid."
|
||||
notify_user_supporting_document_refusal:
|
||||
refusal: "Your supporting documents were refused"
|
||||
notify_user_supporting_document_reminder:
|
||||
reminder_message: "This is a reminder for you to upload your supporting documents."
|
||||
notify_admin_user_supporting_document_refusal:
|
||||
refusal: "Member's supporting document <strong><em>%{NAME}</strong></em> was refused."
|
||||
notify_user_order_is_ready:
|
||||
|
@ -447,6 +447,8 @@ fr:
|
||||
account_invalidated: "Votre compte est invalide."
|
||||
notify_user_supporting_document_refusal:
|
||||
refusal: "Vos pièces justificatives ont été refusées"
|
||||
notify_user_supporting_document_reminder:
|
||||
reminder_message: "Ceci est un message de rappel pour vous inviter à uploader vos pièces justificatives."
|
||||
notify_admin_user_supporting_document_refusal:
|
||||
refusal: "Le justificatif du membre <strong><em>%{NAME}</strong></em> a été refusé."
|
||||
notify_user_order_is_ready:
|
||||
|
@ -402,6 +402,10 @@ en:
|
||||
body:
|
||||
user_supporting_document_files_refusal: "Your supporting documents were refused:"
|
||||
action: "Please re-upload some new supporting documents."
|
||||
notify_user_supporting_document_reminder:
|
||||
subject: "Reminder to upload your supporting documents"
|
||||
body:
|
||||
user_supporting_document_reminder: "This is a reminder for you to upload your supporting documents."
|
||||
notify_admin_user_supporting_document_refusal:
|
||||
subject: "A member's supporting documents were refused"
|
||||
body:
|
||||
|
@ -62,4 +62,9 @@ auto_cancel_authorizations:
|
||||
class: TrainingAuthorizationWorker
|
||||
queue: default
|
||||
|
||||
supporting_documents_reminder_worker:
|
||||
cron: "0 8 * * *" # every day, at 8
|
||||
class: SupportingDocumentsReminderWorker
|
||||
queue: default
|
||||
|
||||
<%= PluginRegistry.insert_code('yml.schedule') %>
|
||||
|
@ -0,0 +1,5 @@
|
||||
class AddSupportingDocumentsReminderSentAtToUsers < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :users, :supporting_documents_reminder_sent_at, :datetime
|
||||
end
|
||||
end
|
@ -4355,7 +4355,8 @@ CREATE TABLE public.users (
|
||||
current_sign_in_ip inet,
|
||||
last_sign_in_ip inet,
|
||||
validated_at timestamp without time zone,
|
||||
mapped_from_sso character varying
|
||||
mapped_from_sso character varying,
|
||||
supporting_documents_reminder_sent_at timestamp(6) without time zone
|
||||
);
|
||||
|
||||
|
||||
@ -9263,6 +9264,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20230825101952'),
|
||||
('20230828073428'),
|
||||
('20230831103208'),
|
||||
('20230901090637'),
|
||||
('20230907124230');
|
||||
|
||||
|
||||
|
8
test/fixtures/notification_types.yml
vendored
8
test/fixtures/notification_types.yml
vendored
@ -607,3 +607,11 @@ notification_type_72:
|
||||
is_configurable: false
|
||||
created_at: 2023-02-16 10:42:39.143888000 Z
|
||||
updated_at: 2023-02-16 10:42:39.143888000 Z
|
||||
|
||||
notification_type_73:
|
||||
id: 73
|
||||
name: notify_user_supporting_document_reminder
|
||||
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
|
83
test/workers/supporting_documents_reminder_worker_test.rb
Normal file
83
test/workers/supporting_documents_reminder_worker_test.rb
Normal file
@ -0,0 +1,83 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
require 'minitest/autorun'
|
||||
#require 'sidekiq/testing'
|
||||
|
||||
class SupportingDocumentsReminderWorkerTest < ActiveSupport::TestCase
|
||||
include ActionMailer::TestHelper
|
||||
setup do
|
||||
@worker = SupportingDocumentsReminderWorker.new
|
||||
|
||||
group = groups(:group_1)
|
||||
@users = User.where(group_id: group.id).members
|
||||
@supporting_document_type_1 = SupportingDocumentType.create!(name: "doc1", groups: [group])
|
||||
@supporting_document_type_2 = SupportingDocumentType.create!(name: "doc2", groups: [group])
|
||||
end
|
||||
|
||||
test 'do nothing if it concerns another group' do
|
||||
group = Group.create!(name: 'test', slug: 'test')
|
||||
SupportingDocumentType.destroy_all
|
||||
supporting_document_type = SupportingDocumentType.create!(name: "doc3", groups: [group])
|
||||
|
||||
@users.each do |user|
|
||||
assert_nil user.supporting_documents_reminder_sent_at
|
||||
end
|
||||
assert_enqueued_emails 0 do
|
||||
@worker.perform
|
||||
end
|
||||
@users.reload.each do |user|
|
||||
assert_nil user.supporting_documents_reminder_sent_at
|
||||
end
|
||||
end
|
||||
|
||||
test 'notify every users who did not upload supporting document files' do
|
||||
@users.each do |user|
|
||||
assert_nil user.supporting_documents_reminder_sent_at
|
||||
end
|
||||
|
||||
assert_enqueued_emails @users.length do
|
||||
@worker.perform
|
||||
end
|
||||
|
||||
@users.reload.each do |user|
|
||||
assert user.supporting_documents_reminder_sent_at
|
||||
end
|
||||
|
||||
assert_enqueued_emails 0 do
|
||||
@worker.perform
|
||||
end
|
||||
end
|
||||
|
||||
test 'notify users even if they have uploaded 1 document of the 2' do
|
||||
@users.each do |user|
|
||||
user.supporting_document_files.create!(supporting_document_type: @supporting_document_type_1,
|
||||
attachment: fixture_file_upload('document.pdf'))
|
||||
end
|
||||
|
||||
assert_enqueued_emails @users.length do
|
||||
@worker.perform
|
||||
end
|
||||
end
|
||||
|
||||
test 'do not notify users if they have uploaded all documents' do
|
||||
@users.each do |user|
|
||||
user.supporting_document_files.create!(supporting_document_type: @supporting_document_type_1,
|
||||
attachment: fixture_file_upload('document.pdf'))
|
||||
user.supporting_document_files.create!(supporting_document_type: @supporting_document_type_2,
|
||||
attachment: fixture_file_upload('document.pdf'))
|
||||
end
|
||||
|
||||
assert_enqueued_emails 0 do
|
||||
@worker.perform
|
||||
end
|
||||
end
|
||||
|
||||
test 'do not notify users if they were created too recently' do
|
||||
@users.update_all(created_at: 2.minutes.ago)
|
||||
|
||||
assert_enqueued_emails 0 do
|
||||
@worker.perform
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user