[FIX #589] Validate birthdate from user input

This commit is contained in:
Mathieu Magnin 2017-07-25 17:00:29 +02:00
parent dae700788f
commit 1aabc6c82b

View file

@ -131,7 +131,10 @@ class Users::DossiersController < UsersController
def update def update
@facade = facade params[:dossier][:id] @facade = facade params[:dossier][:id]
if checked_autorisation_donnees? if individual_errors.any?
flash.alert = individual_errors
redirect_to users_dossier_path(id: @facade.dossier.id)
else
unless Dossier.find(@facade.dossier.id).update_attributes update_params_with_formatted_birthdate unless Dossier.find(@facade.dossier.id).update_attributes update_params_with_formatted_birthdate
flash.alert = @facade.dossier.errors.full_messages flash.alert = @facade.dossier.errors.full_messages
@ -143,9 +146,6 @@ class Users::DossiersController < UsersController
else else
redirect_to url_for(controller: :description, action: :show, dossier_id: @facade.dossier.id) redirect_to url_for(controller: :description, action: :show, dossier_id: @facade.dossier.id)
end end
else
flash.alert = 'Les conditions sont obligatoires.'
redirect_to users_dossier_path(id: @facade.dossier.id)
end end
end end
@ -207,8 +207,20 @@ class Users::DossiersController < UsersController
editable_params editable_params
end end
def checked_autorisation_donnees? def individual_errors
update_params[:autorisation_donnees] == '1' errors = []
if update_params[:autorisation_donnees] != "1"
errors << "La validation des conditions d'utilisation est obligatoire"
end
if update_params[:individual_attributes].present? &&
!/^\d{4}\-\d{2}\-\d{2}$/.match(update_params[:individual_attributes][:birthdate]) &&
!/^\d{2}\/\d{2}\/\d{4}$/.match(update_params[:individual_attributes][:birthdate])
errors << "Le format de la date de naissance doit être JJ/MM/AAAA"
end
errors
end end
def siret def siret