Merge pull request #6254 from tchak/fix-demarches-declaratives
Prevent double processing of declarative dossiers
This commit is contained in:
commit
306c0f9623
5 changed files with 24 additions and 7 deletions
|
@ -8,6 +8,7 @@
|
||||||
# autorisation_donnees :boolean
|
# autorisation_donnees :boolean
|
||||||
# brouillon_close_to_expiration_notice_sent_at :datetime
|
# brouillon_close_to_expiration_notice_sent_at :datetime
|
||||||
# conservation_extension :interval default(0 seconds)
|
# conservation_extension :interval default(0 seconds)
|
||||||
|
# declarative_triggered_at :datetime
|
||||||
# deleted_user_email_never_send :string
|
# deleted_user_email_never_send :string
|
||||||
# en_construction_at :datetime
|
# en_construction_at :datetime
|
||||||
# en_construction_close_to_expiration_notice_sent_at :datetime
|
# en_construction_close_to_expiration_notice_sent_at :datetime
|
||||||
|
@ -655,7 +656,9 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_passer_automatiquement_en_instruction
|
def after_passer_automatiquement_en_instruction
|
||||||
update!(en_instruction_at: Time.zone.now) if self.en_instruction_at.nil?
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
self.declarative_triggered_at = Time.zone.now
|
||||||
|
save!
|
||||||
log_automatic_dossier_operation(:passer_en_instruction)
|
log_automatic_dossier_operation(:passer_en_instruction)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -695,6 +698,7 @@ class Dossier < ApplicationRecord
|
||||||
def after_accepter_automatiquement
|
def after_accepter_automatiquement
|
||||||
self.traitements.build(state: Dossier.states.fetch(:accepte), instructeur_email: nil, motivation: nil, processed_at: Time.zone.now)
|
self.traitements.build(state: Dossier.states.fetch(:accepte), instructeur_email: nil, motivation: nil, processed_at: Time.zone.now)
|
||||||
self.en_instruction_at ||= Time.zone.now
|
self.en_instruction_at ||= Time.zone.now
|
||||||
|
self.declarative_triggered_at = Time.zone.now
|
||||||
|
|
||||||
if attestation.nil?
|
if attestation.nil?
|
||||||
self.attestation = build_attestation
|
self.attestation = build_attestation
|
||||||
|
|
|
@ -606,10 +606,12 @@ class Procedure < ApplicationRecord
|
||||||
when Procedure.declarative_with_states.fetch(:en_instruction)
|
when Procedure.declarative_with_states.fetch(:en_instruction)
|
||||||
dossiers
|
dossiers
|
||||||
.state_en_construction
|
.state_en_construction
|
||||||
|
.where(declarative_triggered_at: nil)
|
||||||
.find_each(&:passer_automatiquement_en_instruction!)
|
.find_each(&:passer_automatiquement_en_instruction!)
|
||||||
when Procedure.declarative_with_states.fetch(:accepte)
|
when Procedure.declarative_with_states.fetch(:accepte)
|
||||||
dossiers
|
dossiers
|
||||||
.state_en_construction
|
.state_en_construction
|
||||||
|
.where(declarative_triggered_at: nil)
|
||||||
.find_each(&:accepter_automatiquement!)
|
.find_each(&:accepter_automatiquement!)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddDeclarativeTriggeredAtToDossiers < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :dossiers, :declarative_triggered_at, :datetime
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2021_05_07_135603) do
|
ActiveRecord::Schema.define(version: 2021_06_04_095054) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -278,6 +278,7 @@ ActiveRecord::Schema.define(version: 2021_05_07_135603) do
|
||||||
t.string "deleted_user_email_never_send"
|
t.string "deleted_user_email_never_send"
|
||||||
t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin
|
t.index "to_tsvector('french'::regconfig, (search_terms || private_search_terms))", name: "index_dossiers_on_search_terms_private_search_terms", using: :gin
|
||||||
t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin
|
t.index "to_tsvector('french'::regconfig, search_terms)", name: "index_dossiers_on_search_terms", using: :gin
|
||||||
|
t.datetime "declarative_triggered_at"
|
||||||
t.index ["archived"], name: "index_dossiers_on_archived"
|
t.index ["archived"], name: "index_dossiers_on_archived"
|
||||||
t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id"
|
t.index ["groupe_instructeur_id"], name: "index_dossiers_on_groupe_instructeur_id"
|
||||||
t.index ["hidden_at"], name: "index_dossiers_on_hidden_at"
|
t.index ["hidden_at"], name: "index_dossiers_on_hidden_at"
|
||||||
|
|
|
@ -9,14 +9,17 @@ RSpec.describe Cron::DeclarativeProceduresJob, type: :job do
|
||||||
let(:nouveau_dossier2) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
let(:nouveau_dossier2) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||||
let(:dossier_recu) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
let(:dossier_recu) { create(:dossier, :en_instruction, :with_individual, procedure: procedure) }
|
||||||
let(:dossier_brouillon) { create(:dossier, procedure: procedure) }
|
let(:dossier_brouillon) { create(:dossier, procedure: procedure) }
|
||||||
|
let(:dossier_repasse_en_construction) { create(:dossier, :en_construction, :with_individual, procedure: procedure) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Timecop.freeze(date)
|
Timecop.freeze(date)
|
||||||
|
dossier_repasse_en_construction.touch(:declarative_triggered_at)
|
||||||
dossiers = [
|
dossiers = [
|
||||||
nouveau_dossier1,
|
nouveau_dossier1,
|
||||||
nouveau_dossier2,
|
nouveau_dossier2,
|
||||||
dossier_recu,
|
dossier_recu,
|
||||||
dossier_brouillon
|
dossier_brouillon,
|
||||||
|
dossier_repasse_en_construction
|
||||||
]
|
]
|
||||||
|
|
||||||
create(:attestation_template, procedure: procedure)
|
create(:attestation_template, procedure: procedure)
|
||||||
|
@ -33,19 +36,21 @@ RSpec.describe Cron::DeclarativeProceduresJob, type: :job do
|
||||||
let(:last_operation) { nouveau_dossier1.dossier_operation_logs.last }
|
let(:last_operation) { nouveau_dossier1.dossier_operation_logs.last }
|
||||||
|
|
||||||
it {
|
it {
|
||||||
expect(nouveau_dossier1.en_instruction?).to be true
|
expect(nouveau_dossier1.en_instruction?).to be_truthy
|
||||||
expect(nouveau_dossier1.en_instruction_at).to eq(date)
|
expect(nouveau_dossier1.en_instruction_at).to eq(date)
|
||||||
expect(last_operation.operation).to eq('passer_en_instruction')
|
expect(last_operation.operation).to eq('passer_en_instruction')
|
||||||
expect(last_operation.automatic_operation?).to be_truthy
|
expect(last_operation.automatic_operation?).to be_truthy
|
||||||
|
|
||||||
expect(nouveau_dossier2.en_instruction?).to be true
|
expect(nouveau_dossier2.en_instruction?).to be_truthy
|
||||||
expect(nouveau_dossier2.en_instruction_at).to eq(date)
|
expect(nouveau_dossier2.en_instruction_at).to eq(date)
|
||||||
|
|
||||||
expect(dossier_recu.en_instruction?).to be true
|
expect(dossier_recu.en_instruction?).to be_truthy
|
||||||
expect(dossier_recu.en_instruction_at).to eq(instruction_date)
|
expect(dossier_recu.en_instruction_at).to eq(instruction_date)
|
||||||
|
|
||||||
expect(dossier_brouillon.brouillon?).to be true
|
expect(dossier_brouillon.brouillon?).to be_truthy
|
||||||
expect(dossier_brouillon.en_instruction_at).to eq(nil)
|
expect(dossier_brouillon.en_instruction_at).to eq(nil)
|
||||||
|
|
||||||
|
expect(dossier_repasse_en_construction.en_construction?).to be_truthy
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue