Merge pull request #10534 from mfo/US/fix-ineligibilite-rules-check-without-rules

Correctif: ETQ admin, je ne peux pas activer l'inéligibilité des dossiers sans règles d'inéligibilité
This commit is contained in:
mfo 2024-06-21 09:47:43 +00:00 committed by GitHub
commit 4caeecadff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 33 additions and 9 deletions

View file

@ -2,7 +2,7 @@
= render Procedure::PendingRepublishComponent.new(procedure: @draft_revision.procedure, render_if: pending_changes?)
= render Conditions::ConditionsErrorsComponent.new(conditions: condition_per_row, source_tdcs: @source_tdcs)
.fr-fieldset
= form_for(@draft_revision, url: change_admin_procedure_ineligibilite_rules_path(@draft_revision.procedure_id), html: { id: 'ineligibilite_form', class: 'width-100' }) do |f|
= form_for(@draft_revision, url: change_admin_procedure_ineligibilite_rules_path(@draft_revision.procedure_id), html: { id: 'ineligibilite_form', class: 'width-100', novalidate: true }) do |f|
.fr-fieldset__element
.fr-toggle.fr-toggle--label-left
= f.check_box :ineligibilite_enabled, class: 'fr-toggle__input', data: @opt

View file

@ -6,7 +6,9 @@ module Administrateurs
end
def change
if draft_revision.update(procedure_revision_params)
draft_revision.assign_attributes(procedure_revision_params)
if draft_revision.validate(:ineligibilite_rules_editor) && draft_revision.save
redirect_to edit_admin_procedure_ineligibilite_rules_path(@procedure)
else
flash[:alert] = draft_revision.errors.full_messages

View file

@ -563,7 +563,7 @@ class Dossier < ApplicationRecord
end
def can_passer_en_construction?
return true if !revision.ineligibilite_enabled
return true if !revision.ineligibilite_enabled || !revision.ineligibilite_rules
!revision.ineligibilite_rules.compute(champs_for_revision(scope: :public))
end

View file

@ -28,6 +28,10 @@ class ProcedureRevision < ApplicationRecord
presence: true,
if: -> { ineligibilite_enabled? },
on: [:ineligibilite_rules_editor, :publication]
validates :ineligibilite_rules,
presence: true,
if: -> { ineligibilite_enabled? },
on: [:ineligibilite_rules_editor, :publication]
serialize :ineligibilite_rules, LogicSerializer

View file

@ -3,5 +3,6 @@ fr:
attributes:
procedure_revision:
ineligibilite_message: Message dinéligibilité
ineligibilite_rules: Les conditions dinéligibilité
hints:
ineligibilite_message: "Ce message sera affiché à lusager si son dossier est bloqué et lui expliquera la raison de son inéligibilité."

View file

@ -220,12 +220,29 @@ describe Administrateurs::IneligibiliteRulesController, type: :controller do
}
end
before { sign_in(admin.user) }
it 'works' do
patch :change, params: params
draft_revision = procedure.reload.draft_revision
expect(draft_revision.ineligibilite_message).to eq('panpan')
expect(draft_revision.ineligibilite_enabled).to eq(true)
expect(response).to redirect_to(edit_admin_procedure_ineligibilite_rules_path(procedure))
context 'when ineligibilite rules is empty' do
it 'fails gracefull without ineligibilite rules' do
patch :change, params: params
draft_revision = procedure.reload.draft_revision
expect(draft_revision.ineligibilite_enabled).to eq(false)
expect(flash[:alert]).to include("Le champ « Les conditions dinéligibilité » doit être rempli")
end
end
context 'when ineligibilite rules is present' do
let(:types_de_champ_public) { [{ type: :drop_down_list, stable_id: 1, options: ['opt'] }] }
before do
procedure.draft_revision.update(ineligibilite_rules: ds_eq(champ_value(1), constant('opt')))
end
it 'works' do
patch :change, params: params
draft_revision = procedure.reload.draft_revision
expect(draft_revision.ineligibilite_message).to eq('panpan')
expect(draft_revision.ineligibilite_enabled).to eq(true)
expect(response).to redirect_to(edit_admin_procedure_ineligibilite_rules_path(procedure))
end
end
end
end