diff --git a/app/components/instructeurs/en_construction_menu_component.rb b/app/components/instructeurs/en_construction_menu_component.rb index a2c930f80..22c4bd398 100644 --- a/app/components/instructeurs/en_construction_menu_component.rb +++ b/app/components/instructeurs/en_construction_menu_component.rb @@ -15,7 +15,7 @@ class Instructeurs::EnConstructionMenuComponent < ApplicationComponent end def menu_label - if dossier.en_construction? + if !dossier.may_repasser_en_construction? t('.request_correction') else t(".revert_en_construction") diff --git a/app/models/concerns/dossier_correctable_concern.rb b/app/models/concerns/dossier_correctable_concern.rb index 2ecb03254..86a14896c 100644 --- a/app/models/concerns/dossier_correctable_concern.rb +++ b/app/models/concerns/dossier_correctable_concern.rb @@ -15,13 +15,13 @@ module DossierCorrectableConcern return if en_construction? - repasser_en_construction!(instructeur: commentaire.instructeur) + repasser_en_construction_with_pending_correction!(instructeur: commentaire.instructeur) end def may_flag_as_pending_correction? return false if pending_corrections.exists? - en_construction? || may_repasser_en_construction? + en_construction? || may_repasser_en_construction_with_pending_correction? end def pending_correction? diff --git a/app/models/dossier.rb b/app/models/dossier.rb index ef7d5fbcd..d6ee4cae7 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -201,6 +201,10 @@ class Dossier < ApplicationRecord end event :repasser_en_construction, after: :after_repasser_en_construction do + transitions from: :en_instruction, to: :en_construction, guard: :can_repasser_en_construction? + end + + event :repasser_en_construction_with_pending_correction, after: :after_repasser_en_construction do transitions from: :en_instruction, to: :en_construction end @@ -581,6 +585,10 @@ class Dossier < ApplicationRecord false end + def can_repasser_en_construction? + !procedure.sva_svr_enabled? + end + def can_repasser_en_instruction? termine? && !user_deleted? end diff --git a/app/views/instructeurs/procedures/_dossier_actions.html.haml b/app/views/instructeurs/procedures/_dossier_actions.html.haml index 6dda325aa..6395cb9c8 100644 --- a/app/views/instructeurs/procedures/_dossier_actions.html.haml +++ b/app/views/instructeurs/procedures/_dossier_actions.html.haml @@ -46,7 +46,7 @@ %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' do Passer en instruction - - elsif Dossier.states[:en_instruction] == state && !with_menu + - elsif Dossier.states[:en_instruction] == state && !with_menu && !sva_svr %li{ 'data-turbo': turbo ? 'true' : 'false' } = button_to repasser_en_construction_instructeur_dossier_path(procedure_id, dossier_id), method: :post, class: 'fr-btn fr-btn--secondary fr-icon-draft-line' do Repasser en construction diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index 62bf1cb5e..8d9f4efa4 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -183,6 +183,7 @@ dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), close_to_expiration: @statut == 'expirant', hidden_by_administration: @statut == 'supprimes_recemment', + sva_svr: @procedure.sva_svr_enabled?, turbo: false, with_menu: false } %tfoot diff --git a/app/views/recherche/index.html.haml b/app/views/recherche/index.html.haml index 71814bd8c..ff17ddc37 100644 --- a/app/views/recherche/index.html.haml +++ b/app/views/recherche/index.html.haml @@ -101,6 +101,7 @@ dossier_is_followed: @followed_dossiers_id.include?(p.dossier_id), close_to_expiration: nil, hidden_by_administration: nil, + sva_svr: p.sva_svr_decision_on.present?, turbo: false, with_menu: false } diff --git a/spec/components/instructeurs/en_contruction_menu_component_spec.rb b/spec/components/instructeurs/en_contruction_menu_component_spec.rb index 491d722f5..58a6f71c1 100644 --- a/spec/components/instructeurs/en_contruction_menu_component_spec.rb +++ b/spec/components/instructeurs/en_contruction_menu_component_spec.rb @@ -49,5 +49,15 @@ RSpec.describe Instructeurs::EnConstructionMenuComponent, type: :component do expect(subject).to have_dropdown_item('Repasser en construction') expect(subject).to have_dropdown_items(count: 3) end + + context 'when procedure is sva' do + let(:dossier) { create(:dossier, :en_instruction, procedure: create(:procedure, :sva)) } + + it 'renders a dropdown' do + expect(subject).to have_dropdown_title('Demander une correction') + expect(subject).to have_dropdown_item('Demander une correction') + expect(subject).to have_dropdown_items(count: 2) + end + end end end diff --git a/spec/models/concern/dossier_correctable_concern_spec.rb b/spec/models/concern/dossier_correctable_concern_spec.rb index 430696505..508b2a0a7 100644 --- a/spec/models/concern/dossier_correctable_concern_spec.rb +++ b/spec/models/concern/dossier_correctable_concern_spec.rb @@ -41,7 +41,7 @@ describe DossierCorrectableConcern do end end - context 'when dossier is not en_instruction' do + context 'when dossier is en_instruction' do let(:dossier) { create(:dossier, :en_instruction) } it 'creates a correction' do @@ -76,6 +76,18 @@ describe DossierCorrectableConcern do expect { dossier.flag_as_pending_correction!(commentaire) }.not_to change { dossier.corrections.pending.count } end end + + context 'when procedure is sva' do + let(:dossier) { create(:dossier, :en_instruction, procedure: create(:procedure, :published, :sva)) } + + it 'creates a correction' do + expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.corrections.pending.count }.by(1) + end + + it 'repasse dossier en_construction' do + expect { dossier.flag_as_pending_correction!(commentaire) }.to change { dossier.state }.to('en_construction') + end + end end describe "#resolve_pending_correction!" do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index c4c26f3d4..dd68f40d1 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1135,6 +1135,17 @@ describe Dossier, type: :model do end end + describe '#can_repasser_en_construction?' do + let(:dossier) { create(:dossier, :en_instruction) } + it { expect(dossier.can_repasser_en_construction?).to be_truthy } + + context 'when procedure is sva' do + let(:dossier) { create(:dossier, :en_instruction, procedure: create(:procedure, :sva)) } + + it { expect(dossier.can_repasser_en_construction?).to be_falsey } + end + end + describe '#can_passer_automatiquement_en_instruction?' do let(:dossier) { create(:dossier, :en_construction, declarative_triggered_at: declarative_triggered_at) } let(:declarative_triggered_at) { nil }