diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index f9e052268..3e322e618 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -302,9 +302,10 @@ module Users def update @dossier = dossier.en_construction? ? dossier.find_editing_fork(dossier.user) : dossier @dossier = dossier_with_champs(pj_template: false) - @can_passer_en_construction_was = @dossier.can_passer_en_construction? - update_dossier_and_compute_errors - @can_passer_en_construction_is = @dossier.can_passer_en_construction? + @can_passer_en_construction_was, @can_passer_en_construction_is = @dossier.track_can_passer_en_construction do + update_dossier_and_compute_errors + end + respond_to do |format| format.turbo_stream do @to_show, @to_hide, @to_update = champs_to_turbo_update(champs_public_attributes_params, dossier.champs.filter(&:public?)) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 343baf06d..e9b0b1e99 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1148,6 +1148,18 @@ class Dossier < ApplicationRecord procedure.accuse_lecture? && termine? end + def track_can_passer_en_construction + if !revision.ineligibilite_enabled + yield + [true, true] # without eligibilite rules, we never reach dossier.champs.visible?, don't cache anything + else + from = can_passer_en_construction? # with eligibilite rules, self.champ[x].visible is cached by passing thru conditions checks + yield + champs.map(&:reset_visible) # we must reset self.champs[x].visible?, because an update occurred and we should re-evaluate champs[x] visibility + [from, can_passer_en_construction?] + end + end + private def create_missing_traitemets diff --git a/spec/system/users/dossier_ineligibilite_spec.rb b/spec/system/users/dossier_ineligibilite_spec.rb index 5bbb25c75..9b9fa9de6 100644 --- a/spec/system/users/dossier_ineligibilite_spec.rb +++ b/spec/system/users/dossier_ineligibilite_spec.rb @@ -179,4 +179,27 @@ describe 'Dossier Inéligibilité', js: true do wait_until { dossier.reload.en_construction? == true } end end + + describe 'ineligibilite_rules does not mess with champs.visible' do + let(:types_de_champ_public) do + [ + { type: :yes_no, libelle: 'l1', stable_id: 1 }, + { type: :yes_no, libelle: 'l2', stable_id: 2, condition: ds_eq(champ_value(1), constant(false)) } + ] + end + let(:ineligibilite_rules) do + ds_eq(champ_value(2), constant(false)) + end + + scenario 'ineligibilite rules without validation on champ ensure to re-process cached champs.visible' do + visit brouillon_dossier_path(dossier) + expect(page).to have_selector(:button, text: "Déposer le dossier", disabled: false) + expect(page).not_to have_content("Vous ne pouvez pas déposer votre dossier") + + within "#champ-1" do + find("label", text: "Non").click + end + expect(page).to have_selector("#champ-2", visible: true) + end + end end