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