feat(procedure_revision.validates): ineligibilite_rules
This commit is contained in:
parent
e3a24d53ea
commit
a011576757
7 changed files with 37 additions and 5 deletions
|
@ -32,6 +32,8 @@ class Procedure::ErrorsSummary < ApplicationComponent
|
|||
|
||||
def error_correction_page(error)
|
||||
case error.attribute
|
||||
when :ineligibilite_rules
|
||||
edit_admin_procedure_ineligibilite_rules_path(@procedure)
|
||||
when :draft_types_de_champ_public
|
||||
tdc = error.options[:type_de_champ]
|
||||
champs_admin_procedure_path(@procedure, anchor: dom_id(tdc.stable_self, :editor_error))
|
||||
|
|
|
@ -293,7 +293,7 @@ class Procedure < ApplicationRecord
|
|||
|
||||
validates_with MonAvisEmbedValidator
|
||||
|
||||
validates_associated :draft_revision, on: :publication
|
||||
validate :validates_associated_draft_revision_with_context
|
||||
validates_associated :initiated_mail, on: :publication
|
||||
validates_associated :received_mail, on: :publication
|
||||
validates_associated :closed_mail, on: :publication
|
||||
|
@ -1020,6 +1020,13 @@ class Procedure < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def validates_associated_draft_revision_with_context
|
||||
return if draft_revision.blank?
|
||||
return if draft_revision.validate(validation_context)
|
||||
|
||||
draft_revision.errors.map { errors.import(_1) }
|
||||
end
|
||||
|
||||
def validate_auto_archive_on_in_the_future
|
||||
return if auto_archive_on.nil?
|
||||
return if auto_archive_on.future?
|
||||
|
|
|
@ -496,6 +496,13 @@ class ProcedureRevision < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def ineligibilite_rules_are_valid?
|
||||
if ineligibilite_rules
|
||||
ineligibilite_rules.errors(types_de_champ_for(scope: :public).to_a)
|
||||
.each { errors.add(:ineligibilite_rules, :invalid) }
|
||||
end
|
||||
end
|
||||
|
||||
def replace_type_de_champ_by_clone(coordinate)
|
||||
cloned_type_de_champ = coordinate.type_de_champ.deep_clone do |original, kopy|
|
||||
ClonePiecesJustificativesService.clone_attachments(original, kopy)
|
||||
|
|
|
@ -606,6 +606,7 @@ en:
|
|||
otp_attempt: 'OTP code (only if you have already activated 2FA)'
|
||||
procedure:
|
||||
zone: This procedure is run by
|
||||
ineligibilite_rules: "Eligibility rules"
|
||||
champs:
|
||||
value: Value
|
||||
default_mail_attributes: &default_mail_attributes
|
||||
|
@ -667,6 +668,10 @@ en:
|
|||
path:
|
||||
taken: is already used for procedure. You cannot use it because it belongs to another administrator.
|
||||
invalid: is not valid. It must countain between 3 and 200 characters among a-z, 0-9, '_' and '-'.
|
||||
procedure_revision:
|
||||
attributes:
|
||||
ineligibilite_rules:
|
||||
invalid: are invalid
|
||||
"dossier/champs":
|
||||
format: "%{message}"
|
||||
attributes:
|
||||
|
|
|
@ -610,6 +610,7 @@ fr:
|
|||
otp_attempt: 'Code OTP (uniquement si vous avez déjà activé 2FA)'
|
||||
procedure:
|
||||
zone: La démarche est mise en œuvre par
|
||||
ineligibilite_rules: "Les règles d’Inéligibilité"
|
||||
champs:
|
||||
value: Valeur du champ
|
||||
default_mail_attributes: &default_mail_attributes
|
||||
|
@ -669,6 +670,10 @@ fr:
|
|||
path:
|
||||
taken: est déjà utilisé par une démarche. Vous ne pouvez pas l’utiliser car il appartient à un autre administrateur.
|
||||
invalid: n’est pas valide. Il doit comporter au moins 3 caractères, au plus 200 caractères et seuls les caractères a-z, 0-9, '_' et '-' sont autorisés.
|
||||
procedure_revision:
|
||||
attributes:
|
||||
ineligibilite_rules:
|
||||
invalid: ne sont pas valides
|
||||
"dossier/champs":
|
||||
format: "%{message}"
|
||||
attributes:
|
||||
|
|
|
@ -74,6 +74,8 @@ describe Procedure::ErrorsSummary, type: :component do
|
|||
end
|
||||
|
||||
describe 'render error for other kind of associated objects' do
|
||||
include Logic
|
||||
|
||||
let(:validation_context) { :publication }
|
||||
let(:procedure) { create(:procedure, attestation_template:, initiated_mail:) }
|
||||
let(:attestation_template) { build(:attestation_template) }
|
||||
|
@ -81,10 +83,12 @@ describe Procedure::ErrorsSummary, type: :component do
|
|||
|
||||
before do
|
||||
[:attestation_template, :initiated_mail].map { procedure.send(_1).update_column(:body, '--invalidtag--') }
|
||||
procedure.draft_revision.update(ineligibilite_enabled: true, ineligibilite_rules: ds_eq(constant(true), constant(1)), ineligibilite_message: 'ko')
|
||||
subject
|
||||
end
|
||||
|
||||
it 'render error nicely' do
|
||||
expect(page).to have_selector("a", text: "Les règles d’inéligibilité")
|
||||
expect(page).to have_selector("a", text: "Le modèle d’attestation")
|
||||
expect(page).to have_selector("a", text: "L’email de notification de passage de dossier en instruction")
|
||||
expect(page).to have_text("n'est pas valide", count: 2)
|
||||
|
|
|
@ -10,16 +10,18 @@ describe TypesDeChampEditor::EditorComponent, type: :component do
|
|||
context 'types_de_champ_public' do
|
||||
let(:is_annotation) { false }
|
||||
it 'does not render private champs errors' do
|
||||
expect(subject).not_to have_text("« private » doit comporter au moins un choix sélectionnable")
|
||||
expect(subject).to have_text("« public » doit comporter au moins un choix sélectionnable")
|
||||
expect(subject).not_to have_text("private")
|
||||
expect(subject).to have_selector("a", text: "public")
|
||||
expect(subject).to have_text("doit comporter au moins un choix sélectionnable")
|
||||
end
|
||||
end
|
||||
|
||||
context 'types_de_champ_private' do
|
||||
let(:is_annotation) { true }
|
||||
it 'does not render public champs errors' do
|
||||
expect(subject).to have_text("« private » doit comporter au moins un choix sélectionnable")
|
||||
expect(subject).not_to have_text("« public » doit comporter au moins un choix sélectionnable")
|
||||
expect(subject).to have_selector("a", "private")
|
||||
expect(subject).to have_text("doit comporter au moins un choix sélectionnable")
|
||||
expect(subject).not_to have_text("public")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue