diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 11a6af34b..f0b236d3d 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -568,7 +568,7 @@ class Dossier < ApplicationRecord end def can_passer_en_instruction? - return false if pending_correction? + return false if procedure.feature_enabled?(:blocking_pending_correction) && pending_correction? true end @@ -579,7 +579,7 @@ class Dossier < ApplicationRecord return false if !can_passer_en_instruction? return true if declarative_triggered_at.nil? && procedure.declarative_en_instruction? - return true if procedure.sva_svr_enabled? && sva_svr_decision_triggered_at.nil? + return true if procedure.sva_svr_enabled? && sva_svr_decision_triggered_at.nil? && !pending_correction? false end @@ -932,6 +932,8 @@ class Dossier < ApplicationRecord .processed_at save! + resolve_pending_correction! + MailTemplatePresenterService.create_commentaire_for_state(self, Dossier.states.fetch(:en_instruction)) if !disable_notification NotificationMailer.send_en_instruction_notification(self).deliver_later diff --git a/app/models/procedure_flipper_actor.rb b/app/models/procedure_flipper_actor.rb new file mode 100644 index 000000000..fe3cf05fe --- /dev/null +++ b/app/models/procedure_flipper_actor.rb @@ -0,0 +1,7 @@ +# Use this when we want to check feature flags on a procedure whithout loading the all procedure +class ProcedureFlipperActor < Struct.new(:procedure_id) do + def flipper_id + "Procedure;#{procedure_id}" + end + end +end diff --git a/app/views/instructeurs/dossiers/_header_actions.html.haml b/app/views/instructeurs/dossiers/_header_actions.html.haml index b42fb8530..f13702df7 100644 --- a/app/views/instructeurs/dossiers/_header_actions.html.haml +++ b/app/views/instructeurs/dossiers/_header_actions.html.haml @@ -9,6 +9,7 @@ close_to_expiration: dossier.close_to_expiration?, hidden_by_administration: dossier.hidden_by_administration?, has_pending_correction: dossier.pending_correction?, + has_blocking_pending_correction: dossier.procedure.feature_enabled?(:blocking_pending_correction) && dossier.pending_correction?, turbo: true, with_menu: true } diff --git a/app/views/instructeurs/procedures/_dossier_actions.html.haml b/app/views/instructeurs/procedures/_dossier_actions.html.haml index 8171590ff..fb0b1435d 100644 --- a/app/views/instructeurs/procedures/_dossier_actions.html.haml +++ b/app/views/instructeurs/procedures/_dossier_actions.html.haml @@ -45,10 +45,10 @@ - if Dossier.states[:en_construction] == state %li{ 'data-turbo': turbo ? 'true' : 'false' } = button_to passer_en_instruction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-icon-edit-line', - disabled: has_pending_correction, "aria-describedby" => has_pending_correction ? "tooltip-passer-en-instruction" : nil do + disabled: has_blocking_pending_correction, "aria-describedby" => has_blocking_pending_correction ? "tooltip-passer-en-instruction" : nil do = t('views.instructeurs.dossiers.passer_en_instruction') - - if has_pending_correction + - if has_blocking_pending_correction %span#tooltip-passer-en-instruction.fr-tooltip.fr-placement{ role: :tooltip, "aria-hidden" => "true" } = t('views.instructeurs.dossiers.passer_en_instruction_blocked_by_pending_correction') diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index e0e7d02ba..e08c28423 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -193,7 +193,7 @@ close_to_expiration: @statut == 'expirant', hidden_by_administration: @statut == 'supprimes_recemment', sva_svr: @procedure.sva_svr_enabled?, - has_pending_correction: p.pending_correction?, + has_blocking_pending_correction: @procedure.feature_enabled?(:blocking_pending_correction) && p.pending_correction?, turbo: false, with_menu: false } diff --git a/app/views/recherche/index.html.haml b/app/views/recherche/index.html.haml index 8c42a9a6b..dc61e9c97 100644 --- a/app/views/recherche/index.html.haml +++ b/app/views/recherche/index.html.haml @@ -105,7 +105,7 @@ close_to_expiration: nil, hidden_by_administration: nil, sva_svr: p.sva_svr_decision_on.present?, - has_pending_correction: p.pending_correction?, + has_blocking_pending_correction: p.pending_correction? && Flipper.enabled?(:blocking_pending_correction, ProcedureFlipperActor.new(procedure_id)), turbo: false, with_menu: false } diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb index 9108a2835..636d7379c 100644 --- a/config/initializers/flipper.rb +++ b/config/initializers/flipper.rb @@ -19,7 +19,8 @@ features = [ :procedure_routage_api, :groupe_instructeur_api_hack, :cojo_type_de_champ, - :sva + :sva, + :blocking_pending_correction ] def database_exists? diff --git a/spec/jobs/process_stalled_declarative_dossier_job_spec.rb b/spec/jobs/process_stalled_declarative_dossier_job_spec.rb index b481f0989..414c764aa 100644 --- a/spec/jobs/process_stalled_declarative_dossier_job_spec.rb +++ b/spec/jobs/process_stalled_declarative_dossier_job_spec.rb @@ -31,18 +31,6 @@ RSpec.describe ProcessStalledDeclarativeDossierJob, type: :job do it { expect(subject.state).to eq('en_construction') } end - - context 'with pending correction' do - let!(:correction) { create(:dossier_correction, dossier:) } - - it { expect(subject.state).to eq('en_construction') } - end - - context 'with resolved correction' do - let!(:correction) { create(:dossier_correction, :resolved, dossier:) } - - it { expect(subject.state).to eq('en_instruction') } - end end context 'dossier already en_instruction' do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index b774349ba..49c1b5e02 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1148,6 +1148,7 @@ describe Dossier, type: :model do let(:last_operation) { dossier.dossier_operation_logs.last } let(:operation_serialized) { last_operation.data } let(:instructeur) { create(:instructeur) } + let!(:correction) { create(:dossier_correction, dossier:) } # correction has a commentaire subject(:passer_en_instruction) { dossier.passer_en_instruction!(instructeur: instructeur) } @@ -1166,6 +1167,13 @@ describe Dossier, type: :model do it { expect { passer_en_instruction }.to change { dossier.commentaires.count }.by(1) } + it "resolve pending correction" do + passer_en_instruction + + expect(dossier.pending_correction?).to be_falsey + expect(correction.reload.resolved_at).to be_present + end + it 'creates a commentaire in the messagerie with expected wording' do passer_en_instruction @@ -1253,13 +1261,24 @@ describe Dossier, type: :model do context 'when there is a pending correction' do before { create(:dossier_correction, dossier:) } - it { expect(dossier.can_passer_en_instruction?).to be_falsey } + it { expect(dossier.can_passer_en_instruction?).to be_truthy } end - context 'when there is a resolved correction' do - before { create(:dossier_correction, :resolved, dossier:) } + context 'when there is a pending correction with procedure blocking_pending_correction feature' do + let(:resolved_at) { nil } - it { expect(dossier.can_passer_en_instruction?).to be_truthy } + before do + Flipper.enable(:blocking_pending_correction, dossier.procedure) + create(:dossier_correction, dossier:, resolved_at: resolved_at) + end + + it { expect(dossier.can_passer_en_instruction?).to be_falsey } + + context 'when there is a resolved correction' do + let(:resolved_at) { Time.current } + + it { expect(dossier.can_passer_en_instruction?).to be_truthy } + end end end diff --git a/spec/views/instructeur/dossiers/show.html.haml_spec.rb b/spec/views/instructeur/dossiers/show.html.haml_spec.rb index 912951062..78af0f3ff 100644 --- a/spec/views/instructeur/dossiers/show.html.haml_spec.rb +++ b/spec/views/instructeur/dossiers/show.html.haml_spec.rb @@ -68,9 +68,15 @@ describe 'instructeurs/dossiers/show', type: :view do context 'with pending correction' do before { create(:dossier_correction, dossier:) } - it 'disable the instruction button' do - expect(subject).to have_button('Passer en instruction', disabled: true) - expect(subject).to have_content('Le passage en instruction est impossible') + it { expect(subject).to have_button('Passer en instruction', disabled: false) } + + context 'with procedure blocking pending correction' do + before { Flipper.enable(:blocking_pending_correction, dossier.procedure) } + + it 'disable the instruction button' do + expect(subject).to have_button('Passer en instruction', disabled: true) + expect(subject).to have_content('Le passage en instruction est impossible') + end end end end