Merge pull request #1335 from consul/under_age_setting

Minimum age setting
This commit is contained in:
Raimond Garcia
2017-01-09 17:46:44 +01:00
committed by GitHub
14 changed files with 35 additions and 27 deletions

View File

@@ -196,6 +196,10 @@ class User < ActiveRecord::Base
@@username_max_length ||= self.columns.find { |c| c.name == 'username' }.limit || 60
end
def self.minimum_required_age
(Setting['min_age_to_participate'] || 16).to_i
end
def show_welcome_screen?
sign_in_count == 1 && unverified? && !organization && !administrator?
end

View File

@@ -23,7 +23,7 @@ class Verification::Management::Document
end
def valid_age?(response)
if under_sixteen?(response)
if under_age?(response)
errors.add(:age, true)
return false
else
@@ -31,8 +31,8 @@ class Verification::Management::Document
end
end
def under_sixteen?(response)
16.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day
def under_age?(response)
User.minimum_required_age.years.ago.beginning_of_day < response.date_of_birth.beginning_of_day
end
def verified?

View File

@@ -36,7 +36,7 @@ class Verification::Residence
def allowed_age
return if errors[:date_of_birth].any?
errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless self.date_of_birth <= 16.years.ago
errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless self.date_of_birth <= User.minimum_required_age.years.ago
end
def document_number_uniqueness

View File

@@ -29,7 +29,7 @@ en:
not_in_census_info: 'Citizens not in the Census can participate in the website with the following permissions:'
please_check_account_data: Please check that the account data above are correct.
title: User management
under_age: You must be over 16 to verify your account.
under_age: "You don't have the required age to verify your account."
verify: Verify
email_label: Email
email_verifications:

View File

@@ -29,7 +29,7 @@ es:
not_in_census_info: 'Las personas no empadronadas pueden participar en el Portal de Gobierno Abierto con las siguientes posibilidades:'
please_check_account_data: Compruebe que los datos anteriores son correctos para proceder a verificar la cuenta completamente.
title: Gestión de usuarios
under_age: Debes ser mayor de 16 años para verificar tu cuenta.
under_age: No tienes edad suficiente para verificar tu cuenta.
verify: Verificar usuario
email_label: Email
email_verifications:

View File

@@ -37,3 +37,4 @@ en:
meta_description: "Site description (SEO)"
meta_keywords: "Keywords (SEO)"
verification_offices_url: Verification offices URL
min_age_to_participate: Minimum age needed to participate

View File

@@ -37,3 +37,4 @@ es:
meta_description: "Descripción del sitio (SEO)"
meta_keywords: "Palabras clave (SEO)"
verification_offices_url: URL oficinas verificación
min_age_to_participate: Edad mínima para participar

View File

@@ -59,7 +59,7 @@ en:
residence_card: Residence card
spanish_id: DNI
document_type_label: Document type
error_not_allowed_age: You must be at least 16 years old
error_not_allowed_age: You don't have the required age to participate
error_not_allowed_postal_code: In order to be verified, you must be registered.
error_verifying_census: The Census was unable to verify your information. Please confirm that your census details are correct by calling to City Council or visit one %{offices}.
error_verifying_census_offices: Citizen Support Office

View File

@@ -59,7 +59,7 @@ es:
residence_card: Tarjeta de residencia
spanish_id: DNI
document_type_label: Tipo de documento
error_not_allowed_age: Hay que tener al menos 16 años
error_not_allowed_age: No tienes la edad mínima para participar
error_not_allowed_postal_code: Para verificarte debes estar empadronado.
error_verifying_census: El Padrón no pudo verificar tu información. Por favor, confirma que tus datos de empadronamiento sean correctos llamando al Ayuntamiento o visitando una %{offices}.
error_verifying_census_offices: oficina de Atención al ciudadano

View File

@@ -39,6 +39,7 @@ Setting.create(key: 'mailer_from_address', value: 'noreply@consul.dev')
Setting.create(key: 'meta_description', value: 'Citizen Participation and Open Government Application')
Setting.create(key: 'meta_keywords', value: 'citizen participation, open government')
Setting.create(key: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/')
Setting.create(key: 'min_age_to_participate', value: '16')
puts "Creating Geozones"
('A'..'Z').each { |i| Geozone.create(name: "District #{i}", external_code: i.ord, census_code: i.ord) }

View File

@@ -94,3 +94,4 @@ Setting['mailer_from_address'] = 'noreply@consul.dev'
# Verification settings
Setting['verification_offices_url'] = 'http://oficinas-atencion-ciudadano.url/'
Setting['min_age_to_participate'] = 16

View File

@@ -63,13 +63,13 @@ feature 'DocumentVerifications' do
end
scenario 'User age is checked' do
expect_any_instance_of(Verification::Management::Document).to receive(:under_sixteen?).and_return(true)
expect_any_instance_of(Verification::Management::Document).to receive(:under_age?).and_return(true)
visit management_document_verifications_path
fill_in 'document_verification_document_number', with: '12345678Z'
click_button 'Check'
expect(page).to have_content "You must be over 16 to verify your account."
expect(page).to have_content "You don't have the required age to verify your account."
end
end

View File

@@ -27,7 +27,7 @@ describe Verification::Residence do
it "should validate user has allowed age" do
residence = Verification::Residence.new({"date_of_birth(3i)"=>"1", "date_of_birth(2i)"=>"1", "date_of_birth(1i)"=>"#{5.year.ago.year}"})
expect(residence).to_not be_valid
expect(residence.errors[:date_of_birth]).to include("You must be at least 16 years old")
expect(residence.errors[:date_of_birth]).to include("You don't have the required age to participate")
end
it "should validate uniquness of document_number" do

View File

@@ -2,36 +2,36 @@ require 'rails_helper'
describe Verification::Management::Document do
describe "#valid_age?" do
it "returns false when the user is younger than sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 12, 31))
it "returns false when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be false
end
it "returns true when the user is sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day))
it "returns true when the user has the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 16.years.ago.month, 16.years.ago.day))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
end
it "returns true when the user is older than sixteen years old" do
census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31))
it "returns true when the user is older than the user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31))
expect(Verification::Management::Document.new.valid_age?(census_response)).to be true
end
end
describe "#under_sixteen?" do
it "returns true when the user is younger than sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be true
describe "#under_age?" do
it "returns true when the user is younger than the user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_age?(census_response)).to be true
end
it "returns false when the user is sixteen years old" do
census_response = double(date_of_birth: Date.new(16.years.ago.year, 16.years.ago.month, 16.years.ago.day))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
it "returns false when the user is user's minimum required age" do
census_response = double(date_of_birth: Date.new(User.minimum_required_age.years.ago.year, User.minimum_required_age.years.ago.month, User.minimum_required_age.years.ago.day))
expect(Verification::Management::Document.new.under_age?(census_response)).to be false
end
it "returns false when the user is older than sixteen years old" do
census_response = double(date_of_birth: Date.new(33.years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_sixteen?(census_response)).to be false
it "returns false when the user is older than user's minimum required age" do
census_response = double(date_of_birth: Date.new((User.minimum_required_age + 10).years.ago.year, 12, 31))
expect(Verification::Management::Document.new.under_age?(census_response)).to be false
end
end
end