Merge pull request #10527 from mfo/US/fix-eligibilite-rules-caching-champs.visible

fix(eligibilite_rules): checking for eligibilites rules should not cache champs.visible
This commit is contained in:
mfo 2024-06-20 14:11:11 +00:00 committed by GitHub
commit 84cdeaa4cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 39 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

View file

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