wip(validates): prefill and validate_champ_value? on all other missing validation checks

This commit is contained in:
mfo 2024-04-01 07:36:14 +02:00
parent 284a10e235
commit e08aa7d28b
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
16 changed files with 16 additions and 0 deletions

View file

@ -5,6 +5,7 @@ class Champs::BooleanChamp < Champ
before_validation :set_value_to_nil, if: -> { value.blank? }
before_validation :set_value_to_false, unless: -> { ([nil, TRUE_VALUE, FALSE_VALUE]).include?(value) }
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates :value, inclusion: [TRUE_VALUE, FALSE_VALUE],
allow_nil: true,
allow_blank: false,

View file

@ -1,5 +1,6 @@
class Champs::CnafChamp < Champs::TextChamp
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/cnaf-input-validation.middleware.ts
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates :numero_allocataire, format: { with: /\A\d{1,7}\z/ }, if: -> { code_postal.present? && validate_champ_value? }
validates :code_postal, format: { with: /\A\w{5}\z/ }, if: -> { numero_allocataire.present? && validate_champ_value? }

View file

@ -1,5 +1,6 @@
class Champs::DepartementChamp < Champs::TextChamp
store_accessor :value_json, :code_region
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validate :value_in_departement_names, unless: -> { value.nil? }
validate :external_id_in_departement_codes, unless: -> { external_id.nil? }
before_save :store_code_region

View file

@ -1,5 +1,6 @@
class Champs::DgfipChamp < Champs::TextChamp
# see https://github.com/betagouv/api-particulier/blob/master/src/presentation/middlewares/dgfip-input-validation.middleware.ts
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates :numero_fiscal, format: { with: /\A\w{13,14}\z/ }, if: -> { reference_avis.present? && validate_champ_value? }
validates :reference_avis, format: { with: /\A\w{13,14}\z/ }, if: -> { numero_fiscal.present? && validate_champ_value? }

View file

@ -1,4 +1,5 @@
class Champs::DossierLinkChamp < Champ
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validate :value_integerable, if: -> { value.present? }, on: :prefill
private

View file

@ -5,6 +5,7 @@ class Champs::DropDownListChamp < Champ
OTHER = '__other__'
delegate :options_without_empty_value_when_mandatory, to: :type_de_champ
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validate :value_is_in_options, unless: -> { value.blank? || drop_down_other? }
def render_as_radios?

View file

@ -1,5 +1,6 @@
class Champs::EmailChamp < Champs::TextChamp
include EmailSanitizableConcern
before_validation -> { sanitize_email(:value) }
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates :value, allow_blank: true, format: { with: StrictEmailValidator::REGEXP }, if: :validate_champ_value?
end

View file

@ -1,5 +1,6 @@
class Champs::EngagementJuridiqueChamp < Champ
# cf: https://communaute.chorus-pro.gouv.fr/documentation/creer-un-engagement/#1522314752186-a34f3662-0644b5d1-16c22add-8ea097de-3a0a
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates_with ExpressionReguliereValidator,
expression_reguliere: /([A-Z]|[0-9]|\-|\_|\+|\/)+/,
expression_reguliere_error_message: "Le numéro d'EJ ne peut contenir que des caractères alphanumérique et les caractères spéciaux suivant : “-“ ; “_“ ; “+“ ; “/“",

View file

@ -3,6 +3,7 @@ class Champs::EpciChamp < Champs::TextChamp
before_validation :on_departement_change
before_validation :on_epci_name_changes
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validate :code_departement_in_departement_codes, unless: -> { code_departement.nil? }
validate :external_id_in_departement_epci_codes, unless: -> { code_departement.nil? || external_id.nil? }
validate :value_in_departement_epci_names, unless: -> { code_departement.nil? || external_id.nil? || value.nil? }

View file

@ -1,3 +1,4 @@
class Champs::ExpressionReguliereChamp < Champ
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates_with ExpressionReguliereValidator, if: :validate_champ_value?
end

View file

@ -1,4 +1,5 @@
class Champs::IbanChamp < Champ
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates_with IbanValidator, if: :validate_champ_value?
after_validation :format_iban

View file

@ -1,4 +1,5 @@
class Champs::MultipleDropDownListChamp < Champ
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validate :values_are_in_options, if: -> { value.present? }
def options?

View file

@ -1,6 +1,7 @@
class Champs::PieceJustificativeChamp < Champ
FILE_MAX_SIZE = 200.megabytes
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates :piece_justificative_file,
size: { less_than: FILE_MAX_SIZE },
if: -> { !type_de_champ.skip_pj_validation }

View file

@ -1,4 +1,5 @@
class Champs::RegionChamp < Champs::TextChamp
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validate :value_in_region_names, unless: -> { value.nil? }
validate :external_id_in_region_codes, unless: -> { external_id.nil? }

View file

@ -1,6 +1,7 @@
class Champs::RNAChamp < Champ
include RNAChampAssociationFetchableConcern
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates :value, allow_blank: true, format: {
with: /\AW[0-9A-Z]{9}\z/, message: I18n.t(:not_a_rna, scope: 'activerecord.errors.messages')
}, if: :validate_champ_value?

View file

@ -1,6 +1,7 @@
class Champs::TitreIdentiteChamp < Champ
FILE_MAX_SIZE = 20.megabytes
ACCEPTED_FORMATS = ['image/png', 'image/jpeg']
# TODO: if: -> { validate_champ_value? || validation_context == :prefill }
validates :piece_justificative_file, content_type: ACCEPTED_FORMATS, size: { less_than: FILE_MAX_SIZE }
def main_value_name