fix(ineligibilite_rules): cache bust champs.visible after checking for ineligibilite rules

Update app/models/dossier.rb

Co-authored-by: Paul Chavard <github@paul.chavard.net>
This commit is contained in:
mfo 2024-06-17 16:41:51 +02:00
parent 8cbf4753ff
commit 9adb1bcf49
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 16 additions and 3 deletions

View file

@ -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?))

View file

@ -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