Merge pull request #559 from AyuntamientoMadrid/address
removes unnecessary address from users
This commit is contained in:
@@ -12,12 +12,8 @@ class Verification::LetterController < ApplicationController
|
||||
|
||||
def create
|
||||
@letter = Verification::Letter.new(user: current_user)
|
||||
if @letter.save
|
||||
redirect_to edit_letter_path
|
||||
else
|
||||
flash.now.alert = t('verification.letter.create.alert.failure')
|
||||
render :new
|
||||
end
|
||||
@letter.save
|
||||
redirect_to edit_letter_path
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
class Address < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
end
|
||||
@@ -12,7 +12,6 @@ class User < ActiveRecord::Base
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
has_one :address
|
||||
has_one :administrator
|
||||
has_one :moderator
|
||||
has_one :organization
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
class Verification::Letter
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :user, :address, :verification_code
|
||||
attr_accessor :user, :verification_code
|
||||
|
||||
validates :user, presence: true
|
||||
validates :address, presence: true
|
||||
validate :correct_address
|
||||
|
||||
def save
|
||||
valid? &&
|
||||
letter_requested! &&
|
||||
update_user_address
|
||||
end
|
||||
|
||||
def address
|
||||
@address ||= CensusApi.new(user).address
|
||||
letter_requested!
|
||||
end
|
||||
|
||||
def letter_requested!
|
||||
@@ -37,32 +30,6 @@ class Verification::Letter
|
||||
user.letter_verification_code == verification_code
|
||||
end
|
||||
|
||||
def correct_address
|
||||
errors.add(:address, I18n.t('verification.letter.errors.address_not_found')) unless
|
||||
address.present?
|
||||
end
|
||||
|
||||
def update_user_address
|
||||
user.address = Address.new(parsed_address)
|
||||
user.save
|
||||
end
|
||||
|
||||
def parsed_address
|
||||
{ postal_code: address[:codigo_postal],
|
||||
street: address[:nombre_via],
|
||||
street_type: address[:sigla_via],
|
||||
number: address[:numero_via],
|
||||
number_type: address[:nominal_via],
|
||||
letter: address[:letra_via],
|
||||
portal: address[:portal],
|
||||
stairway: address[:escalera],
|
||||
floor: address[:planta],
|
||||
door: address[:puerta],
|
||||
km: address[:km],
|
||||
neighbourhood: address[:nombre_barrio],
|
||||
district: address[:nombre_distrito] }
|
||||
end
|
||||
|
||||
def increase_letter_verification_tries
|
||||
user.update(letter_verification_tries: user.letter_verification_tries += 1)
|
||||
end
|
||||
|
||||
@@ -75,8 +75,6 @@ en:
|
||||
success_html: "Thank you for requesting a maximum security code in a few days we will send it to the address on your census data."
|
||||
offices: "Oficinas de Atención al Ciudadano"
|
||||
offices_url: "http://www.madrid.es/portales/munimadrid/es/Inicio/El-Ayuntamiento/Atencion-al-ciudadano/Oficinas-de-Atencion-al-Ciudadano?vgnextfmt=default&vgnextchannel=5b99cde2e09a4310VgnVCM1000000b205a0aRCRD"
|
||||
alert:
|
||||
failure: "We could not verify your address with the Census please try again later"
|
||||
edit:
|
||||
title: "Empieza a participar"
|
||||
confirmation_code: "Introduce aquí el código de máxima seguridad cuando recibas tu carta"
|
||||
@@ -91,7 +89,6 @@ en:
|
||||
errors:
|
||||
letter_not_sent: "We have not sent you the letter with the code yet"
|
||||
incorect_code: "Incorrect confirmation code"
|
||||
address_not_found: "Address not found"
|
||||
verified_user:
|
||||
show:
|
||||
title: "Available information"
|
||||
|
||||
@@ -75,8 +75,6 @@ es:
|
||||
success_html: "Gracias por solicitar tu <b>código de máxima seguridad (solo necesario para las votaciones finales)</b>, en unos días te lo enviaremos a la dirección que figura en tus datos del padrón. Recuerda que puedes ahorrar el envío recogiendo tu código en cualquiera de las %{offices}."
|
||||
offices: "Oficinas de Atención al Ciudadano"
|
||||
offices_url: "http://www.madrid.es/portales/munimadrid/es/Inicio/El-Ayuntamiento/Atencion-al-ciudadano/Oficinas-de-Atencion-al-Ciudadano?vgnextfmt=default&vgnextchannel=5b99cde2e09a4310VgnVCM1000000b205a0aRCRD"
|
||||
alert:
|
||||
failure: "No podemos verificar tu dirección con el Padrón, por favor inténtalo otra vez más tarde"
|
||||
edit:
|
||||
title: "Empieza a participar"
|
||||
confirmation_code: "Introduce aquí el código de máxima seguridad cuando recibas tu carta"
|
||||
@@ -91,7 +89,6 @@ es:
|
||||
errors:
|
||||
letter_not_sent: "Aún no te hemos enviado la carta con el código"
|
||||
incorect_code: "Código de verificación incorrecto"
|
||||
address_not_found: "No se ha encontrado una dirección"
|
||||
verified_user:
|
||||
show:
|
||||
title: "Información disponible"
|
||||
|
||||
27
db/migrate/20150926113052_drop_addresses_table.rb
Normal file
27
db/migrate/20150926113052_drop_addresses_table.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
class DropAddressesTable < ActiveRecord::Migration
|
||||
def self.up
|
||||
drop_table :addresses
|
||||
end
|
||||
|
||||
def self.down
|
||||
create_table "addresses", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.string "street"
|
||||
t.string "street_type"
|
||||
t.string "number"
|
||||
t.string "number_type"
|
||||
t.string "letter"
|
||||
t.string "portal"
|
||||
t.string "stairway"
|
||||
t.string "floor"
|
||||
t.string "door"
|
||||
t.string "km"
|
||||
t.string "neighbourhood"
|
||||
t.string "district"
|
||||
t.string "postal_code"
|
||||
t.string "toponymy"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
20
db/schema.rb
20
db/schema.rb
@@ -28,26 +28,6 @@ ActiveRecord::Schema.define(version: 20150926115929) do
|
||||
add_index "activities", ["actionable_id", "actionable_type"], name: "index_activities_on_actionable_id_and_actionable_type", using: :btree
|
||||
add_index "activities", ["user_id"], name: "index_activities_on_user_id", using: :btree
|
||||
|
||||
create_table "addresses", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.string "street"
|
||||
t.string "street_type"
|
||||
t.string "number"
|
||||
t.string "number_type"
|
||||
t.string "letter"
|
||||
t.string "portal"
|
||||
t.string "stairway"
|
||||
t.string "floor"
|
||||
t.string "door"
|
||||
t.string "km"
|
||||
t.string "neighbourhood"
|
||||
t.string "district"
|
||||
t.string "postal_code"
|
||||
t.string "toponymy"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "administrators", force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
@@ -37,10 +37,6 @@ class CensusApi
|
||||
data[:datos_vivienda][:item][:codigo_postal]
|
||||
end
|
||||
|
||||
def address
|
||||
response[:get_habita_datos_response][:get_habita_datos_return][:datos_vivienda][:item]
|
||||
end
|
||||
|
||||
def valid?
|
||||
return false unless data[:datos_habitante][:item].present?
|
||||
|
||||
@@ -53,6 +49,6 @@ class CensusApi
|
||||
end
|
||||
|
||||
def stubbed_response
|
||||
{:get_habita_datos_response=>{:get_habita_datos_return=>{:hay_errores=>false, :datos_habitante=>{:item=>{:fecha_nacimiento_string=>"31-12-1980", :identificador_documento=>"12345678Z", }}, :datos_vivienda=>{:item=>{:codigo_postal=>"28013", :escalera=>"4", :km=>"0", :letra_via=>"B", :nombre_barrio=>"JUSTICIA", :nombre_distrito=>"CENTRO", :nombre_via=>"ALCALÁ", :nominal_via=>"NUM", :numero_via=>"1", :planta=>"PB", :portal=>"1", :puerta=>"DR", :sigla_via=>"CALLE"}}}}}
|
||||
{:get_habita_datos_response=>{:get_habita_datos_return=>{:hay_errores=>false, :datos_habitante=>{:item=>{:fecha_nacimiento_string=>"31-12-1980", :identificador_documento=>"12345678Z", }}, :datos_vivienda=>{:item=>{:codigo_postal=>"28013"}}}}}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,7 +58,6 @@ FactoryGirl.define do
|
||||
|
||||
factory :verification_letter, class: Verification::Letter do
|
||||
user
|
||||
address
|
||||
end
|
||||
|
||||
factory :lock do
|
||||
@@ -67,12 +66,6 @@ FactoryGirl.define do
|
||||
locked_until Time.now
|
||||
end
|
||||
|
||||
factory :address do
|
||||
street_type "Calle"
|
||||
street "Alcalá"
|
||||
number "1"
|
||||
end
|
||||
|
||||
factory :verified_user do
|
||||
document_number '12345678Z'
|
||||
document_type 'dni'
|
||||
|
||||
@@ -49,21 +49,6 @@ feature 'Verify Letter' do
|
||||
expect(page).to have_content "Incorrect confirmation code"
|
||||
end
|
||||
|
||||
scenario "Error accessing address from CensusApi" do
|
||||
user = create(:user, residence_verified_at: Time.now,
|
||||
confirmed_phone: "611111111",
|
||||
letter_sent_at: 1.day.ago)
|
||||
|
||||
login_as(user)
|
||||
visit new_letter_path
|
||||
|
||||
allow_any_instance_of(CensusApi).to receive(:address).and_return(nil)
|
||||
|
||||
click_button "Send me a letter with the code"
|
||||
|
||||
expect(page).to have_content "We could not verify your address with the Census please try again later"
|
||||
end
|
||||
|
||||
scenario "Deny access unless verified residence" do
|
||||
user = create(:user)
|
||||
|
||||
|
||||
@@ -17,11 +17,6 @@ describe 'Verification::Letter' do
|
||||
expect(letter).to_not be_valid
|
||||
end
|
||||
|
||||
it "should not be valid without an address" do
|
||||
letter.address = {}
|
||||
expect(letter).to_not be_valid
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe "save" do
|
||||
@@ -36,23 +31,6 @@ describe 'Verification::Letter' do
|
||||
expect(user.letter_requested_at).to be
|
||||
end
|
||||
|
||||
it "should update address" do
|
||||
expect(user.address).to have_attributes({
|
||||
postal_code: "28013",
|
||||
street: "ALCALÁ",
|
||||
street_type: "CALLE",
|
||||
number: "1",
|
||||
number_type: "NUM",
|
||||
letter: "B",
|
||||
portal: "1",
|
||||
stairway: "4",
|
||||
floor: "PB",
|
||||
door: "DR",
|
||||
km: "0",
|
||||
neighbourhood: "JUSTICIA",
|
||||
district: "CENTRO"
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe "#verified?" do
|
||||
|
||||
Reference in New Issue
Block a user