diff --git a/app/models/verification/management/document.rb b/app/models/verification/management/document.rb index 6c9a8897f..fb23528b8 100644 --- a/app/models/verification/management/document.rb +++ b/app/models/verification/management/document.rb @@ -17,7 +17,21 @@ class Verification::Management::Document end def in_census? - CensusApi.new.call(document_type, document_number).valid? + response = CensusApi.new.call(document_type, document_number) + response.valid? && valid_age?(response) + end + + def valid_age?(response) + if under_sixteen?(response) + errors.add(:age, true) + return false + else + return true + end + end + + def under_sixteen?(response) + 16.years.ago.year < response.date_of_birth.to_date.year end def verified? @@ -28,7 +42,4 @@ class Verification::Management::Document user.update(verified_at: Time.now) if user? end -end - - - +end \ No newline at end of file diff --git a/app/views/management/document_verifications/invalid_document.html.erb b/app/views/management/document_verifications/invalid_document.html.erb index ee7120c9b..3652e1db7 100644 --- a/app/views/management/document_verifications/invalid_document.html.erb +++ b/app/views/management/document_verifications/invalid_document.html.erb @@ -1,5 +1,9 @@
- <%= t("management.document_verifications.not_in_census") %> + <% if @document_verification.errors[:age].any? %> + <%= t("management.document_verifications.under_age") %> + <% else %> + <%= t("management.document_verifications.not_in_census") %> + <% end %>
<%= render 'management/user_permissions', diff --git a/config/locales/management.en.yml b/config/locales/management.en.yml index 34a30a832..51e869dae 100644 --- a/config/locales/management.en.yml +++ b/config/locales/management.en.yml @@ -41,6 +41,7 @@ en: already_verified: "This user account is already verified." in_census_has_following_permissions: "This user can participate in the website with the following permissions:" not_in_census: "This document is not registered in Madrid." + under_age: "You must be over 16 to verify your account." not_in_census_info: "Citizens not in the Census can participate in the website with the following permissions:" has_no_account_html: "In order to create an account, go to %{link} and click in 'Register' in the upper-left part of the screen." verify: "Verify" diff --git a/config/locales/management.es.yml b/config/locales/management.es.yml index d56fb625d..f3aa2fbeb 100644 --- a/config/locales/management.es.yml +++ b/config/locales/management.es.yml @@ -41,6 +41,7 @@ es: already_verified: "Esta cuenta de usuario ya está verificada." in_census_has_following_permissions: "Este usuario puede participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" not_in_census: "Este documento no está registrado en el Padrón Municipal de Madrid." + under_age: "Debes ser mayor de 16 años para verificar tu cuenta." not_in_census_info: "Las personas no empadronadas en Madrid pueden participar en el Portal de Gobierno Abierto del Ayuntamiento de Madrid con las siguientes posibilidades:" has_no_account_html: "Para crear un usuario entre en %{link} y haga clic en la opción 'Registrarse' en la parte superior derecha de la pantalla." verify: "Verificar usuario" diff --git a/spec/features/management/document_verifications_spec.rb b/spec/features/management/document_verifications_spec.rb index 4a437a661..674349815 100644 --- a/spec/features/management/document_verifications_spec.rb +++ b/spec/features/management/document_verifications_spec.rb @@ -62,4 +62,14 @@ feature 'DocumentVerifications' do expect(page).to have_content "Document number: 12345H" end + scenario 'User age is checked' do + expect_any_instance_of(Verification::Management::Document).to receive(:under_sixteen?).and_return(true) + + visit management_document_verifications_path + fill_in 'document_verification_document_number', with: '1234' + click_button 'Check' + + expect(page).to have_content "You must be over 16 to verify your account." + end + end \ No newline at end of file