Fix #4807 48h before closing a procedure, notify users their draft is not submitted
This commit is contained in:
parent
ea3022a292
commit
e61c53f267
5 changed files with 86 additions and 1 deletions
|
@ -104,4 +104,11 @@ class DossierMailer < ApplicationMailer
|
|||
|
||||
mail(from: NO_REPLY_EMAIL, to: instructeur.email, subject: @subject)
|
||||
end
|
||||
|
||||
def notify_dossier_not_submitted(dossier)
|
||||
@subject = "Attention : votre dossier n'est pas déposé."
|
||||
@dossier = dossier
|
||||
|
||||
mail(to: dossier.user.email, subject: @subject)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,8 @@ class Dossier < ApplicationRecord
|
|||
|
||||
TAILLE_MAX_ZIP = 50.megabytes
|
||||
|
||||
REMAINING_TIME_BEFORE_CLOSING = 2.days
|
||||
|
||||
has_one :etablissement, dependent: :destroy
|
||||
has_one :individual, validate: false, dependent: :destroy
|
||||
has_one :attestation, dependent: :destroy
|
||||
|
@ -186,6 +188,19 @@ class Dossier < ApplicationRecord
|
|||
scope :without_brouillon_expiration_notice_sent, -> { where(brouillon_close_to_expiration_notice_sent_at: nil) }
|
||||
scope :without_en_construction_expiration_notice_sent, -> { where(en_construction_close_to_expiration_notice_sent_at: nil) }
|
||||
|
||||
scope :brouillon_close_to_procedure_closing_date, -> do
|
||||
# select users who have submitted dossier for the given 'procedures.id'
|
||||
users_who_submitted =
|
||||
state_not_brouillon
|
||||
.joins(:groupe_instructeur)
|
||||
.where("groupe_instructeurs.procedure_id = procedures.id")
|
||||
.select(:user_id)
|
||||
# select dossier in brouillon where procedure closes in two days and for which the user has not submitted a Dossier
|
||||
brouillon.joins(:procedure)
|
||||
.where(procedures: { auto_archive_on: Time.zone.today + REMAINING_TIME_BEFORE_CLOSING })
|
||||
.where.not(user: users_who_submitted)
|
||||
end
|
||||
|
||||
scope :for_procedure, -> (procedure) { includes(:user, :groupe_instructeur).where(groupe_instructeurs: { procedure: procedure }) }
|
||||
scope :for_api_v2, -> { includes(procedure: [:administrateurs], etablissement: [], individual: []) }
|
||||
|
||||
|
@ -690,4 +705,12 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.notify_draft_not_submitted
|
||||
brouillon_close_to_procedure_closing_date
|
||||
.includes(:procedure, :user)
|
||||
.find_each do |dossier|
|
||||
DossierMailer.notify_dossier_not_submitted(dossier).deliver_later
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
- content_for(:title, "#{@subject}")
|
||||
|
||||
%p
|
||||
Bonjour,
|
||||
|
||||
%p
|
||||
Le dossier n°#{@dossier.id} pour la démarche «
|
||||
%strong
|
||||
#{@dossier.procedure.libelle}
|
||||
» est en brouillon.
|
||||
%p
|
||||
Si vous souhaitez que ce dossier soit pris en compte, il vous faut le déposer avant le
|
||||
#{l(@dossier.procedure.auto_archive_on - 1.day, format: '%-d %B %Y')} à 23h59, date de cloture de la démarche.
|
||||
%p
|
||||
Pour cela, affichez le dossier avec le bouton ci-dessous, vérifiez votre dossier puis
|
||||
cliquez sur le bouton
|
||||
%strong
|
||||
'Déposer le dossier'
|
||||
%p
|
||||
Si vous ne souhaitez plus déposer le dossier, vous n'avez rien à faire.
|
||||
|
||||
= round_button('Afficher votre dossier', dossier_url(@dossier), :primary)
|
||||
|
||||
= render partial: "layouts/mailers/signature"
|
|
@ -52,6 +52,10 @@ class DossierMailerPreview < ActionMailer::Preview
|
|||
def notify_automatic_deletion_to_administration
|
||||
DossierMailer.notify_automatic_deletion_to_administration([deleted_dossier, deleted_dossier], administration_email)
|
||||
end
|
||||
|
||||
def notify_dossier_not_submitted
|
||||
DossierMailer.notify_dossier_not_submitted(draft)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
@ -76,7 +80,7 @@ class DossierMailerPreview < ActionMailer::Preview
|
|||
end
|
||||
|
||||
def procedure
|
||||
Procedure.new(id: 1234, libelle: 'Dotation d’Équipement des Territoires Ruraux - Exercice 2019', service: service, logo: Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png'))
|
||||
Procedure.new(id: 1234, libelle: 'Dotation d’Équipement des Territoires Ruraux - Exercice 2019', service: service, logo: Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png'), auto_archive_on: Time.zone.today + Dossier::REMAINING_TIME_BEFORE_CLOSING)
|
||||
end
|
||||
|
||||
def service
|
||||
|
|
|
@ -1152,6 +1152,33 @@ describe Dossier do
|
|||
it { expect(Dossier.for_procedure(procedure_2)).to contain_exactly(dossier_2_1) }
|
||||
end
|
||||
|
||||
describe '#notify_draft_not_submitted' do
|
||||
let!(:user1) { create(:user) }
|
||||
let!(:user2) { create(:user) }
|
||||
let!(:procedure_closed_in_time) { create(:procedure, auto_archive_on: Time.zone.today + Dossier::REMAINING_TIME_BEFORE_CLOSING) }
|
||||
let!(:procedure_closed_later) { create(:procedure, auto_archive_on: Time.zone.today + Dossier::REMAINING_TIME_BEFORE_CLOSING + 1.day) }
|
||||
let!(:procedure_closed_before) { create(:procedure, auto_archive_on: Time.zone.today + Dossier::REMAINING_TIME_BEFORE_CLOSING - 1.day) }
|
||||
|
||||
# user 1 has three draft dossiers where one is for procedure that closes in two days ==> should trigger one mail
|
||||
let!(:draft_in_time) { create(:dossier, user: user1, procedure: procedure_closed_in_time) }
|
||||
let!(:draft_before) { create(:dossier, user: user1, procedure: procedure_closed_before) }
|
||||
let!(:draft_later) { create(:dossier, user: user1, procedure: procedure_closed_later) }
|
||||
|
||||
# user 2 submitted a draft and en_construction dossier for the same procedure ==> should not trigger the mail
|
||||
let!(:draft_in_time2) { create(:dossier, :en_construction, user: user2, procedure: procedure_closed_in_time) }
|
||||
let!(:submitted_in_time2) { create(:dossier, user: user2, procedure: procedure_closed_in_time) }
|
||||
|
||||
before do
|
||||
allow(DossierMailer).to receive(:notify_dossier_not_submitted).and_return(double(deliver_later: nil))
|
||||
Dossier.notify_draft_not_submitted
|
||||
end
|
||||
|
||||
it 'notifies draft is not submitted' do
|
||||
expect(DossierMailer).to have_received(:notify_dossier_not_submitted).once
|
||||
expect(DossierMailer).to have_received(:notify_dossier_not_submitted).with(draft_in_time)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#geo_position' do
|
||||
let(:lat) { "46.538192" }
|
||||
let(:lon) { "2.428462" }
|
||||
|
|
Loading…
Reference in a new issue