Merge pull request #5777 from tchak/remove-titre-identite-after-processing

Remove titres identite after a dossier is processed
This commit is contained in:
Paul Chavard 2020-12-10 16:23:54 +01:00 committed by GitHub
commit 984818c051
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 0 deletions

View file

@ -41,6 +41,7 @@ class Champ < ApplicationRecord
:exclude_from_view?,
:repetition?,
:dossier_link?,
:titre_identite?,
to: :type_de_champ
scope :updated_since?, -> (date) { where('champs.updated_at > ?', date) }

View file

@ -591,6 +591,7 @@ class Dossier < ApplicationRecord
end
save!
remove_titres_identite!
NotificationMailer.send_closed_notification(self).deliver_later
log_dossier_operation(instructeur, :accepter, self)
end
@ -604,6 +605,7 @@ class Dossier < ApplicationRecord
end
save!
remove_titres_identite!
NotificationMailer.send_closed_notification(self).deliver_later
log_automatic_dossier_operation(:accepter, self)
end
@ -616,6 +618,7 @@ class Dossier < ApplicationRecord
end
save!
remove_titres_identite!
NotificationMailer.send_refused_notification(self).deliver_later
log_dossier_operation(instructeur, :refuser, self)
end
@ -628,10 +631,15 @@ class Dossier < ApplicationRecord
end
save!
remove_titres_identite!
NotificationMailer.send_without_continuation_notification(self).deliver_later
log_dossier_operation(instructeur, :classer_sans_suite, self)
end
def remove_titres_identite!
champs.filter(&:titre_identite?).map(&:piece_justificative_file).each(&:purge_later)
end
def check_mandatory_champs
(champs + champs.filter(&:repetition?).flat_map(&:champs))
.filter(&:mandatory_and_blank?)

View file

@ -197,6 +197,10 @@ class TypeDeChamp < ApplicationRecord
type_champ == TypeDeChamp.type_champs.fetch(:number)
end
def titre_identite?
type_champ == TypeDeChamp.type_champs.fetch(:titre_identite)
end
def public?
!private?
end

View file

@ -1370,4 +1370,58 @@ describe Dossier do
expect(dossier.champs_for_export(dossier.procedure.types_de_champ_for_export)).to eq(dossier_second_revision.champs_for_export(dossier_second_revision.procedure.types_de_champ_for_export))
end
end
describe "remove_titres_identite!" do
let(:dossier) { create(:dossier, :en_instruction, :followed) }
let(:type_de_champ_titre_identite) { create(:type_de_champ_titre_identite, procedure: dossier.procedure) }
let(:champ_titre_identite) { create(:champ_titre_identite, type_de_champ: type_de_champ_titre_identite) }
let(:type_de_champ_titre_identite_vide) { create(:type_de_champ_titre_identite, procedure: dossier.procedure) }
let(:champ_titre_identite_vide) { create(:champ_titre_identite, type_de_champ: type_de_champ_titre_identite_vide) }
before do
champ_titre_identite_vide.piece_justificative_file.purge
dossier.champs << champ_titre_identite
dossier.champs << champ_titre_identite_vide
end
it "clean up titres identite on accepter" do
expect(champ_titre_identite.piece_justificative_file.attached?).to be_truthy
expect(champ_titre_identite_vide.piece_justificative_file.attached?).to be_falsey
perform_enqueued_jobs do
dossier.accepter!(dossier.followers_instructeurs.first, "yolo!")
end
expect(champ_titre_identite.piece_justificative_file.attached?).to be_falsey
end
it "clean up titres identite on refuser" do
expect(champ_titre_identite.piece_justificative_file.attached?).to be_truthy
expect(champ_titre_identite_vide.piece_justificative_file.attached?).to be_falsey
perform_enqueued_jobs do
dossier.refuser!(dossier.followers_instructeurs.first, "yolo!")
end
expect(champ_titre_identite.piece_justificative_file.attached?).to be_falsey
end
it "clean up titres identite on classer_sans_suite" do
expect(champ_titre_identite.piece_justificative_file.attached?).to be_truthy
expect(champ_titre_identite_vide.piece_justificative_file.attached?).to be_falsey
perform_enqueued_jobs do
dossier.classer_sans_suite!(dossier.followers_instructeurs.first, "yolo!")
end
expect(champ_titre_identite.piece_justificative_file.attached?).to be_falsey
end
context 'en_construction' do
let(:dossier) { create(:dossier, :en_construction, :followed) }
it "clean up titres identite on accepter_automatiquement" do
expect(champ_titre_identite.piece_justificative_file.attached?).to be_truthy
expect(champ_titre_identite_vide.piece_justificative_file.attached?).to be_falsey
perform_enqueued_jobs do
dossier.accepter_automatiquement!
end
expect(champ_titre_identite.piece_justificative_file.attached?).to be_falsey
end
end
end
end